We wouldn't be able to help you with the information you have provided because the problem is very likely that your data is in the wrong form, but you haven't shown us the data. Check that every row of the value that you pass to the addRows() method is an array. This value should be an array of arrays, e.g. [[1, 2, 3], [4, 5, 6]].
The error message suggests there could be a null value instead of a row, but I honestly don't know what it will do in that case since it doesn't make any sense to have a null row (except to ignore it). Also make sure you have the right number of columns in your rows (3 in your case). On Mon, Oct 9, 2017 at 6:50 AM, test grank <[email protected]> wrote: > 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 [email protected]. > 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 > <https://groups.google.com/d/msgid/google-visualization-api/29fe39da-77b2-44ba-8bd5-aeaef3689097%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> [email protected] <[email protected]> 5CC, Cambridge MA -- 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 [email protected]. To post to this group, send email to [email protected]. 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/CAOtcSJNu5a9TuC7gV-rLCGmkBkN73K9M90xjeoCbrUiuFXckuw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
