我已經使用谷歌圖表很長一段時間了。昨天我試着在我的網頁上添加一個組合圖表,導致Google Chrome中的cannot read property 'count' of undefined
和Firefox中的b is undefined
。我一直在努力解決這個問題,但至今沒有成功。我讀到它可能是原型的原因,但其他圖表工作正常。 以下是jsfiddle上this issue的示例。無法讀取谷歌圖表中未定義的屬性'count'
代碼:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="combochart2.1" style="width: 900px; height: 500px;"></div>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart1);
function drawChart1() {
var data = new google.visualization.DataTable();
var cols = 5 ;
var rows = 4;
var cell_values = new Array();
var col_header=new Array();
var text=new Array();
data.addColumn('string', 'Questions');
col_header= "apples, orange, pineapple, rocket, spaceship".split(",");
cell_values= "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20".split(",");
text= "Q1,Q2,Q3,Q4".split(",");
for (var k=0;k<cols;k++)
{
data.addColumn('number',col_header[k]);
}
// Add empty rows
data.addRows(rows);
var index=0;
//setting cell values
for(var i=0;i<rows;i++)
{
//setting first column values
data.setCell(i,0,text[i]);
for(var q=1;q<(cols+1);q++){
//setting other cell valeus
data.setCell(i,q,parseInt(cell_values[index]));
index++;
}
}
var options = {
title: 'Fruits',
vAxis: 'No of consumers',
hAxis: {title: 'Set No',titleTextStyle: {bold: true,color: '#000' }},
height: 260,width: 500,
seriesType: "bars"
};
var chart = new google.visualization.ComboChart(document.getElementById('combochart2.1'));
chart.draw(data, options);
}
</script>
作爲JSFiddle的補充,您應該始終在代碼中包含您的代碼。否則,如果外部鏈接改變,該問題將對用戶無用。 – hennes 2014-09-04 06:31:01