Hello guys, I am trying to implement the line chart for the values stored 
in the database. but I am getting the following error.
*Uncaught (in promise) Error: Every row given must be either null or an 
array.*



This is my code  : -

<?php
$conn = mysqli_connect("localhost","root","","test");
$clid= 'xxxxxxxx';
$result = $conn->query("SELECT clicks, impressions,date FROM reportbydate 
WHERE clientid='$clid'");      
    $table = array();
    $table['cols'] = array(
    array('label' => 'clicks','type' => 'number'),
    array('label' => 'impressions','type' => 'number')
    );
    $rows = array();
    while ($nt = $result->fetch_assoc())
    {
    $temp = array();
    $temp[] = array('v' => $nt['clicks'], 'f' =>NULL);
    $temp[] = array('v' => $nt['impressions'], 'f' =>NULL);
    $rows[] = array('c' => $temp);
    }
    $table['rows'] = $rows;
    $jsonTable = json_encode($table);
    echo $jsonTable;
?>
<html>
  <head>
    <script type="text/javascript" 
src="https://www.gstatic.com/charts/loader.js";></script>
    <script type="text/javascript">

google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawLineColors);

function drawLineColors() {
      var data = new google.visualization.DataTable();
      data.addColumn('number', 'Date');
      data.addColumn('number', 'Clicks');
  data.addColumn('number', 'Impressions');
  
      data.addRows([JSON.parse(<?php echo json_encode($jsonTable);?>)]);
  
      var options = {
        hAxis: {
          title: 'Date'
        },
        vAxis: {
          title: 'Clicks vs Impressions'
        },
        colors: ['#a52714', '#097138']
      };

      var chart = new 
google.visualization.LineChart(document.getElementById('chart_div'));
      chart.draw(data, options);
  }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px"></div>
  </body>
</html> 
 

</script>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/29fe39da-77b2-44ba-8bd5-aeaef3689097%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to