JavaScript More than two Google Charts on a single page? more than google,more than one google voice number,more

I've been struggling with this problem for a while now, and it seems like google has made a lot of minor changes to the Google Charts API over the years, which has been making it even harder to find an answer for why my charts aren't working.

I am simply trying to display more than two of the same chart type (Bar graphs) on a single page. Just today, I found a solution that allowed me to display 2 charts at once (link: "Google Charts stops drawing after first chart"), but this was only a minor win because I really need more than 2 charts to show, and this solution just forces one graph to render before the other.

Here is my current code:

Javascript

google.load('visualization', '1', {packages: ['corechart', 'line', 'bar']});      

google.setOnLoadCallback(drawStuff);

      function drawStuff() {
          
        // Courses_Played Data  
        var data = new google.visualization.arrayToDataTable([
          ['', 'Number of Rounds Played'],
          ["Ken McDonald", 10],
          ["ASU Karsten", 8],
          ["TPC Scotts...", 7],
          ["Ahwatukee", 3],
          ['Other', 3]
        ]);
          
        // Courses_played Options
        var options = {
          title: '',
          width: 440,
          height: 215,
          legend: { position: 'none' },
          axes: {x: {0: { side: 'bottom' }}},
          bar: { groupWidth: "70%" },
          colors: ['darkgreen'],
        };
          
          
        // Course_Scores Data
        var data2 = new google.visualization.arrayToDataTable([
          ['', 'Number of Rounds Played'],
          ["TPC Scotts...", 81],
          ["ASU Karst...", 83],
          ["Ken McDonald", 87],
          ["Ahwatukee", 90],
        ]);  
          
        //Course_Scores Options
          var options2 = {
          title: '',
          width: 440,
          height: 215,
          legend: { position: 'none' },
          axes: {x: {0: { side: 'bottom' }}},
          vAxis:{ viewWindow:{ min:60 }},
          bar: { groupWidth: "70%" },
          colors: ['darkgreen'],
        };
          
          
        var chart = new google.charts.Bar(document.getElementById('Courses_Played'));
google.visualization.events.addOneTimeListener(chart, 'ready', function(){

        var chart2 = new google.charts.Bar(document.getElementById('Course_Scores'));
        // Convert the Classic options to Material options.
        chart2.draw(data2, google.charts.Bar.convertOptions(options2));
          });
          
      chart.draw(data, google.charts.Bar.convertOptions(options));    
      };
Answer:1

The problem in Google Charts is that you can call google.charts.load() only once. So you need to include all the packages in this single function call and call this from head of the webpage.

You can include multiple packages like this:

<head><script type="text/javascript">
google.charts.load("current", {packages:["corechart","bar"]});
</script>
</head>

This solved my problem and allowed me to display multiple charts on a single page without changing any code.

To verify check this: https://developers.google.com/chart/interactive/docs/basic_load_libs#basic-library-loading

Answer:2

I think you're having a problem with the current version, which has issues.
You shouldn't need to wait for one chart to load before loading another.

Here is an example that loads version 41 --> all 3 charts draw, without waiting on another.

google.charts.load('41', {packages: ['bar']});
google.charts.setOnLoadCallback(drawStuff);

function drawStuff() {
    // Courses_Played Data
    var data = new google.visualization.arrayToDataTable([
        ['', 'Number of Rounds Played'],
        ["Ken McDonald", 10],
        ["ASU Karsten", 8],
        ["TPC Scotts...", 7],
        ["Ahwatukee", 3],
        ['Other', 3]
    ]);

    // Courses_played Options
    var options = {
        title: '',
        width: 440,
        height: 215,
        legend: { position: 'none' },
        axes: {x: {0: { side: 'bottom' }}},
        bar: { groupWidth: "70%" },
        colors: ['darkgreen'],
    };

    // Courses_Played2014 Data
    var data3 = new google.visualization.arrayToDataTable([
        ['', 'Number of Rounds Played'],
        ["Ken McDonald", 14],
        ["ASU Karsten", 12],
        ["TPC Scotts...", 11],
        ["Ahwatukee", 7],
        ['Other', 7]
    ]);

    // Courses_played2014 Options
    var options3 = {
        title: '',
        width: 440,
        height: 215,
        legend: { position: 'none' },
        axes: {x: {0: { side: 'bottom' }}},
        bar: { groupWidth: "70%" },
        colors: ['darkgreen'],
    };


    // Course_Scores Data
    var data2 = new google.visualization.arrayToDataTable([
        ['', 'Number of Rounds Played'],
        ["TPC Scotts...", 81],
        ["ASU Karst...", 83],
        ["Ken McDonald", 87],
        ["Ahwatukee", 90],
    ]);

    //Course_Scores Options
    var options2 = {
        title: '',
        width: 440,
        height: 215,
        legend: { position: 'none' },
        axes: {x: {0: { side: 'bottom' }}},
        vAxis:{ viewWindow:{ min:60 }},
        bar: { groupWidth: "70%" },
        colors: ['darkgreen'],
    };

    var chart = new google.charts.Bar(document.getElementById('Courses_Played'));
    var chart2 = new google.charts.Bar(document.getElementById('Course_Scores'));
    var chart3 = new google.charts.Bar(document.getElementById('Courses_Played2014'));

    chart.draw(data, google.charts.Bar.convertOptions(options));
    chart2.draw(data2, google.charts.Bar.convertOptions(options2));
    chart3.draw(data3, google.charts.Bar.convertOptions(options3));
};
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://www.google.com/jsapi"></script>

<div id="Courses_Played"></div>
<div id="Courses_Played2014"></div>
<div id="Course_Scores"></div>
Answer:3

If there is a Javascript object with multiple levels, as in: myObject = { a: 12, obj11: { obj111: 'John', b:13, obj1111: { a:15, b: 35 }...

If there is a Javascript object with multiple levels, as in: myObject = { a: 12, obj11: { obj111: 'John', b:13, obj1111: { a:15, b: 35 }...

  1. fetch array keys in php
  2. fetch array key jquery

I was wondering is there a way to split key/value pairs of objects and insert them into array so that I get array of objects. Here is the code: let grades = [5,5,6,7,6,7,9,10,8,6] let gradesSpread =...

I was wondering is there a way to split key/value pairs of objects and insert them into array so that I get array of objects. Here is the code: let grades = [5,5,6,7,6,7,9,10,8,6] let gradesSpread =...

  1. split object key value
  2. split object in keyshot
  3. javascript split object by key
  4. keyshot split object surfaces

I am using a layout list with Masonry (and animOnScroll on top of it). I want to add bootstrap dropdowns to my list items, but Masonry inserts directly into every dropdown <li> DOM node a style="...

I am using a layout list with Masonry (and animOnScroll on top of it). I want to add bootstrap dropdowns to my list items, but Masonry inserts directly into every dropdown <li> DOM node a style="...

I have a javascript array which get created dynamically in this format. [{prdName: "Testing2"}, {prdName: "Testing2,Testing3"}, {markets: "Testing5"}, {markets: "Testing5,Testing6"}] I want to ...

I have a javascript array which get created dynamically in this format. [{prdName: "Testing2"}, {prdName: "Testing2,Testing3"}, {markets: "Testing5"}, {markets: "Testing5,Testing6"}] I want to ...

  1. removing duplicate value in excel
  2. remove duplicate value from array in php
  3. remove duplicate value from array
  4. remove duplicate value from array javascript
  5. remove duplicate value from array in java
  6. remove duplicate value from list in python
  7. remove duplicate value from array in swift 4
  8. remove duplicate value from array in jquery
  9. how to remove duplicate values in sql
  10. remove duplicate value from list in c#
  11. remove duplicate value from list in java
  12. remove duplicate value from array swift
  13. remove duplicate value in array js
  14. remove duplicate value from multidimensional array in php
  15. remove duplicate value from arraylist in java
  16. remove duplicate value from associative array in php
  17. remove duplicate value from arraylist in android
  18. remove duplicate value online
  19. remove duplicate value in sql query
  20. remove duplicate value from array in c