Google Charts gives me error when bringing queries with an empty conditional

0

Good afternoon, I'm currently working with the Google Chart charts and it works almost perfect, I'm working with a mail system and I want you to show me a graph of the shipments that have been made during the year, the problem is that if a client has no shipments during that year the system throws me this error (and what I really want is that if you do not have shipments all data is zero):

Data column(s) for axis #0 cannot be of type string

Next the code

<!DOCTYPE html>
<html lang="en">
<head>
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script>
 google.load("visualization", "1", {packages:["corechart"]});
 google.setOnLoadCallback(dibujarGrafico);
 function dibujarGrafico() {
   // Tabla de datos: valores y etiquetas de la gráfica
   var data = google.visualization.arrayToDataTable([
     ['Mes', 'Campañas'],
     <?php
     $unavariable= $row = pg_fetch_assoc($result);
       if(isset($result)){
           while($row = pg_fetch_assoc($result)){
              $mes = "cualquiera";
             
             echo "['".$mes."', ".$row['cantidad']."],";
             }
       }else{
            $mes2="Cero";
            $nada=0;
            echo "['".$mes2."', '".$nada."'],";
       }
       ?>

   ]);


   var options = {
     title: 'Campañas año <?php echo $ano;?>',
     width: 900,
     height: 500,
     colors: ['#1a581b']
   }
   // Dibujar el gráfico

   new google.visualization.ColumnChart(
   //ColumnChart sería el tipo de gráfico a dibujar
     document.getElementById('GraficoGoogleChart-ejemplo-1')
   ).draw(data, options);
 }

</script>
</head>
<body>


<!-- Display the pie chart -->
<div id="GraficoGoogleChart-ejemplo-1" style="width: 800px; height: 600px">
</body>
</html>
    
asked by Luis Alfredo Serrano Díaz 22.05.2018 в 19:33
source

0 answers