Hi,

Hoping someone can spot the unintentional error in the below.  The code 
only generates the error message 'c.getTimezoneOffset is not a function' 
and no chart.  echo $jsonTable; generates the data below:

{"cols":[{"label":"Date_time","type":"datetime"},{"label":"Temperature","type":"number"}],"rows":[{"c":[{"v":"2020-05-10
 
20:31:04"},{"v":36}]},{"c":[{"v":"2020-05-10 
20:30:03"},{"v":36}]},{"c":[{"v":"2020-05-10 
20:29:04"},{"v":36.1}]},{"c":[{"v":"2020-05-10 
20:28:03"},{"v":36.1}]},{"c":[{"v":"2020-05-10 
20:27:03"},{"v":36.1}]},{"c":[{"v":"2020-05-10 
20:26:04"},{"v":36.2}]},{"c":[{"v":"2020-05-10 
20:25:04"},{"v":36.2}]},{"c":[{"v":"2020-05-10 
20:24:04"},{"v":36.2}]},{"c":[{"v":"2020-05-10 
20:23:04"},{"v":36.1}]},{"c":[{"v":"2020-05-10 
20:22:04"},{"v":36.1}]},{"c":[{"v":"2020-05-10 
20:21:04"},{"v":36.1}]},{"c":[{"v":"2020-05-10 
20:20:03"},{"v":36.1}]},{"c":[{"v":"2020-05-10 
20:19:03"},{"v":36.1}]},{"c":[{"v":"2020-05-10 20:18:03"},{"v":36.1}]}

(obviously it generates 1000 records, but I've truncated it above).

Code used:


<?php
$servername = "localhost";
$username = "removed";
$password = "removed";
$dbname = "temperature_DB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * from tempLog order by datetime DESC LIMIT 1000";


if ($result = $conn->query($sql)) {
{
$rows = array();
$table = array();
$table['cols'] = array (
array('label' => 'Date_time', 'type' => 'datetime'),
array('label' => 'Temperature', 'type' => 'number')
);

while ($row = $result->fetch_assoc()) {
$temp = array();
$temp[] = array('v' => (string) $row['datetime']);
$temp[] = array('v' => (float) $row['temperature']);
$rows[] = array('c' => $temp);
}
}

}

$table['rows'] = $rows;
$jsonTable = json_encode($table);

$conn->close();
?>

  <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']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {        
        var data = new google.visualization.DataTable(<?php echo 
$jsonTable; ?>);

        var options = {
          title: 'Temperature Log',
          curveType: 'function',
          legend: { position: 'bottom' }
        };

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

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/5f87b6f2-6301-45e0-8499-cbe6eea96324%40googlegroups.com.

Reply via email to