I'm trying to display numbers and datetime from sql server in a LineChart. But I'm getting the following error in my html page : "Undefined is not a function"
My html code :
<html>
<head>
<script src="script/jquery-1.11.1.js" type="text/javascript"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></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() {
var jsonData = $.ajax({
url: "getData.php",
dataType:"json",
async: false
}).responseText;
// 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});
}
google.setOnLoadCallback(drawChart);
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
My php :
<?php
include("connect.php");
$rq = " SELECT dateUpdate, W_3P FROM real_time_measure";
$result = mysqli_query($link, $rq);
$table = array();
$table['cols'] = array(
array('label' => 'datetime', 'type' => 'datetime'),
array('label' => 'mesure', 'type' => 'number')
);
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$temp = array();
// each column needs to have data inserted via the $temp array
$temp[] = array('v' => $r['dateUpdate']);
$temp[] = array('v' => (float) $r['W_3P']);
// etc...
// insert the temp array into $rows
$rows[] = array('c' => $temp);
}
// populate the table with rows of data
$table['rows'] = $rows;
// return the JSON data
$jsonTable = json_encode($table);
echo $jsonTable;
?>
EDIT This code returns : {"cols":[{"label":"datetime","type":"string"},{"label":"mesure","type":"number"}],"rows":[{"c":[{"v":"2014-04-15 21:35:14"},{"v":12.4}]},{"c":[{"v":"2014-04-15 21:35:14"},{"v":12.4}]},...]}]}
This code comes from other topics in this forum. Does anybody know where this error come from? Thanks for your help, Jordan.
UPDATE
If i change async to true in the drawChart function. The error returned is : "Table has no columns. "
UPDATE II
If I past json data in the vizualisation.LineChart() function it's work. So the issue must be in $.ajax function. ??