我想使用谷歌圖表,但不是硬編碼它。我想用一個while循環來填充圖表。這裏是我的代碼:谷歌圖表問題
var drinks = data.split("\n");
var ii = 0;
//create chart
var data = new google.visualization.DataTable();
data.addColumn('string', 'Beer');
data.addColumn('number', 'Beers');
var rows = drinks.length/2;
data.addRows(76);
//iprints data
while( ii < drinks.length-1) {
data.setValue(ii, drinks[ii], drinks[ii+1] );
ii = ii +2;
}
// Set chart options
var options = {'title':'Drinks',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
我的數據來自一個格式如此的文本文件。
名 # 名 # 名 #
當我看着鉻控制檯我得到時執行代碼,使圖表此錯誤:
Uncaught Error: Invalid column index drinks[ii]. Should be an integer in the range [0-1].
爲什麼我的帖子被拒絕1? – searayman 2012-04-19 21:31:12