Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

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>
like image 619
Sahil Avatar asked Jan 10 '23 21:01

Sahil


1 Answers

Your vAxis option is specified incorrectly; it should be an object, not a string:

vAxis: {
    title: 'No of consumers'
}
like image 187
asgallant Avatar answered Feb 12 '23 14:02

asgallant