简体   繁体   English

无法读取谷歌图表中未定义的属性“计数”

[英]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 undefinedb 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.

相关问题 无法读取未定义的Google图表的属性“ DataTable” - Cannot read property 'DataTable' of undefined google charts Google图表:无法读取未定义的属性“ 0” - Google Charts: Cannot read property '0' of undefined 创建视图时,Google图表会抛出“无法读取未定义的属性&#39;1&#39;” - Google Charts throws “cannot read property '1' of undefined” when creating a view Google Charts API:无法读取未定义的属性“ toArrays” - Google Charts API : Cannot read property 'toArrays' of undefined JS-Google图表-无法读取未定义的属性&#39;getChartLayoutInterface&#39; - JS - Google charts - Cannot read property 'getChartLayoutInterface' of undefined 无法读取 React with Google 图表中未定义的属性“推送” - Cannot read property 'push' of undefined in React with Google charts 无法读取Google Geo Charts中未定义的属性&#39;arrayToDataTable&#39; - Cannot read property 'arrayToDataTable' of undefined at Google Geo Charts 无法读取媒体资源Google图表 - Cannot read property google charts 谷歌图表错误:无法读取未定义的属性“长度”; Google图表中的调试错误 - Google charts error:Cannot read property 'length' of undefined; Debugging error in Google Charts 浮动图表:无法读取未定义的属性“插件” - flot charts: Cannot read property 'plugins' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM