2011-12-27 5 views
2

は私のjavascriptを許して..私は次のように1行を持つページのループでそれを呼び出すGoogleのチャートコードを取り、関数として、一度それを使用したい:Googleのチャート

JavaScript関数(ヘッダ内)

var taxes, purchase_costs, closing_costs, holding_costs, cost_money, commissions, theid; 

function costPieChart(taxes,purchase_costs,closing_costs,holding_costs,cost_money,commissions,theid) 
{ 

    google.load("visualization", "1", {packages:["corechart"]}); 
    google.setOnLoadCallback(drawChart); 


    function drawChart() { 
    var data = new google.visualization.DataTable(); 
    data.addColumn('string', 'Item'); 
    data.addColumn('number', 'Cost'); 
    data.addRows([ 
     ['Taxes', taxes], 
     ['Purchase Costs', purchase_costs], 
     ['Closing Costs', closing_costs], 
     ['Holding Costs', holding_costs], 
     ['Cost of Money', cost_money], 
     ['Commissions', commissions] 
    ]); 

    var options = { 
    width: 190, legend: 'none', 
     colors:['red','blue', '993399', 'grey', 'ff6600', 'green'] 
    }; 

    var chart = new google.visualization.PieChart(document.getElementById(theid)); 
    chart.draw(data, options); 
    } 
    } 

次にHTMLでPHPループによって

<script type="text/javascript"> 
     costPieChart(<?php echo round($method['tax_amount_for_days']).', '.round($method['closing_costs_purchase']).', '. 
       round($method['holding_costs']).', '.round($method['cost_of_money']).', '.round($method['commissions_amount']).", 'chart_div".$i."'" ; ?>); 

    </script> 
     <div class="chart_wrap"> <div id="chart_div<? echo $i ?>"></div> </div> 

ループが動作するJavaScriptとHTMLをレンダリングするが、残念ながら、かわいいlilの円グラフは存在しません。助けて?

答えて

2

drawChart機能を呼び出すことはありません。円グラフを描くには、ある時点でそれを呼び出す必要があります。

var options = { 
width: 190, legend: 'none', 
    colors:['red','blue', '993399', 'grey', 'ff6600', 'green'] 
}; 

var chart = new google.visualization.PieChart(document.getElementById(theid)); 
chart.draw(data, options); 

drawChart(); // <--- like this 

}

+0

動作しません。そして、それはgooglesのチャートのスクリプトで視覚的に呼ばれたことはありませんでした。多分、Googleは彼らの最後にそれを呼び出します。 – Robert

+0

@ロバート - 私は本当によく分かりません。しかし、その円グラフを描画するには、間違いなくその関数を呼び出す必要があります。なぜそれが壊れてしまったかについては、わからない。エラーが発生していますか? –

+0

ここで、_Uncaughtエラー:型が一致しません。 chart_div1の値が列インデックス1_ の型番号と一致せず、各インスタンスに対して繰り返します。 – Robert

関連する問題