How to put two Google Charts on the same page

2

I am creating a web application in which it uses two graphics fed by the bank. I use google's api, google charts. However, only the first graphic appears while the other is blank.

    <html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script></head><body><scripttype="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data1 = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

        var options1 = {
          title: 'teste 1',
          is3D: true,
        };

        var chart1 = new google.visualization.PieChart(document.getElementById('teste1'));
        chart1.draw(data1, options1);
      }
    </script>


   <div id="teste1" style="width: 600px; height: 300px;"></div>


 <script type="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

        var options = {
          title: 'teste 2',
          is3D: true,
        };

        var chart = new google.visualization.PieChart(document.getElementById('teste'));
        chart1.draw(data, options);
      }
    </script>

    <div id="teste" style="width: 600px; height: 300px;"></div>
  </body>
</html>

    
asked by anonymous 16.06.2016 / 04:35

1 answer

2

Google Charts has a time error that prevents more than one chart from loading on the same page.

Google has managed to fix this error, I advise you to read this documentation on the subject:

link

Also take a look at this page that talks about the same subject as yours and how they managed to fix it:

link

This question has also been answered in the OS, here is the link:

link

Take a look at how to draw multiple charts:

link

    
16.06.2016 / 04:43