[英]cannot read property 'count' of undefined in google charts
I have been using google charts for quite some time now.我已经使用谷歌图表有一段时间了。 Yesterday I tried adding a Combo Chart on my webpage which resulted in cannot read property 'count' of undefined
in Google Chrome and b is undefined
in Firefox.昨天我尝试在我的网页上添加一个组合图表,导致cannot read property 'count' of undefined
Google Chrome cannot read property 'count' of undefined
而b is undefined
在 Firefox 中b is undefined
。 I have been trying to fix this but no success till now.我一直在尝试解决这个问题,但直到现在都没有成功。 I read that it might be cause of prototype but still other charts are working fine.我读到这可能是原型的原因,但其他图表仍然可以正常工作。 Here's the example of this issue on jsfiddle.这是jsfiddle上这个问题的例子。
Code:代码:
<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>
Your vAxis
option is specified incorrectly;您的vAxis
选项指定不正确; it should be an object, not a string:它应该是一个对象,而不是一个字符串:
vAxis: {
title: 'No of consumers'
}
I used Bar charts lib which was working fine.我使用了运行良好的条形图库。 suddenly it started giving the above error and I found that it is loading 48 version of charts lib.突然它开始出现上述错误,我发现它正在加载 48 版本的图表库。 So I specified the "46.2" version instead of "current" while calling the "loading" statement.所以我在调用“loading”语句时指定了“46.2”版本而不是“current”。
google.charts.load('46.1', { 'packages': ['bar'] });
As you have given ref of " https://www.google.com/jsapi ", it will load " https://www.gstatic.com/charts/loader.js " and which will load "current" version of charts javascript.由于您已经给出了“ https://www.google.com/jsapi ”的引用,它将加载“ https://www.gstatic.com/charts/loader.js ”并加载“当前”版本的图表javascript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.