I was try to make simple line graph using Google chart that retrieve data from mysql. My json work but when I try call it in full coding, it say "c.getTimezoneOffset is not a function".
Here my json php
<?php
include("config.php");
$query = "SELECT * FROM reading";
$sql = mysqli_query($con, $query);
if (!$sql) {
die("Error running $sql: " . mysql_error());
}
$results = array(
'cols' => array (
array('label' => 'Date', 'type' => 'datetime'),
array('label' => 'API', 'type' => 'number')
),
'rows' => array()
);
while($row = mysqli_fetch_assoc($sql)) {
$year=date("Y", strtotime($row['time']));
$month=date("m", strtotime($row['time']));
$day=date("d", strtotime($row['time']));
$hour=date("H", strtotime($row['time']));
$minute=date("i", strtotime($row['time']));
$second=date("s", strtotime($row['time']));
$results['rows'][] = array('c' => array(
array('v' => "time($year, $month, $day, $hour, $minute, $second)"),
array('v' => $row['api'])
));
}
$json = json_encode($results, JSON_NUMERIC_CHECK);
echo $json;
?>
Here my json
{"cols":[{"label":"Date","type":"datetime"},
"label":"API","type":"number"}],
"rows":[{"c":[{"v":"time(2016, 05, 22, 12, 24, 26)"},{"v":26}]},
{"c":[{"v":"time(2016, 05, 22, 12, 24, 41)"},{"v":26}]},
{"c":[{"v":"time(2016, 05, 22, 12, 24, 56)"},{"v":27}]}]}
And here is my html coding
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
$.ajax({
url: 'getData.php',
dataType: 'json',
success: function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240});
}
});
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
c.getTimezoneOffset
by yourself, andc
comes from json object which you injected from PHP script, or that error comes from google lib? – Pau