Quantcast
Channel: Últimos conteúdos
Viewing all articles
Browse latest Browse all 14190

Problema com Google Chart

$
0
0

Fala galera. Comecei a usar o Google Chart para gerar gráficos a partir dos dados do meu banco. Ótima ferramenta, mas esbarrei num problema aqui e queria saber se alguém já passou por ele e se conseguiu resolver.

 

Quando coloco um gráfico, funciona normal.

O problema é quando eu quero colocar mais de um gráfico na mesma página, já que os gráficos chamam o mesmo método. Tentei renomear mas não funcionou.

Segue o código dos gráficos:

 

 

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
//gráfico 1
<script type="text/javascript">
      google.load("visualization", "1.1", {packages:["bar"]});
      google.setOnLoadCallback(drawStuff);
 
      function drawStuff() {
        var data = new google.visualization.arrayToDataTable([
          ['Move', '%'],
          ["Masculino", <?php echo $percent_masc ?>],
          ['Feminino', <?php echo $percent_fem ?>]
        ]);
 
        var options = {
          title: 'Percentual de pacientes',
          width: 380,
          legend: { position: 'none' },
          chart: { subtitle: 'Divisão por sexo' },
          axes: {
            x: {
              0: { side: 'top', label: ''} // Top x-axis.
            }
          },
          bar: { groupWidth: "90%" }
        };
 
        var chart = new google.charts.Bar(document.getElementById('top_x_div'));
        // Convert the Classic options to Material options.
        chart.draw(data, google.charts.Bar.convertOptions(options));
      };
    </script>
 
//gráfico2
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
 
        var data = google.visualization.arrayToDataTable([
          ['Effort', 'Amount given'],
          ['My all',     100],
 ['My all',     50],
        ]);
 
        var options = {
          pieHole: 0.5,
          pieSliceTextStyle: {
            color: 'black',
          },
          legend: 'none'
        };
 
        var chart = new google.visualization.PieChart(document.getElementById('donut_single'));
        chart.draw(data, options);
      }
    </script>
 
 
O erro é o seguinte:
 
You called the draw() method with the wrong type of data rather than a DataTable or DataView
 

Viewing all articles
Browse latest Browse all 14190