I'm working on a chart from MySQL, it worked fine as a linechart but when I changed to annotationchart it gave me the following error due to it needing a date/time, I changed the type to datetime (was string) and still have the error.
Type mismatch. Value 2014-07-23 19:03:16 does not match type datetime
Original Code
<?php
$con=mysql_connect("ip","user","pass") or die("Failed to connect with database!!!!");
mysql_select_db("db", $con);
$sth = mysql_query("SELECT * FROM db.table");
$data = array (
'cols' => array(
array('id' => 'date', 'label' => 'date', 'type' => 'datetime'),
array('id' => 'Temp', 'label' => 'Temp', 'type' => 'number'),
array('id' => 'Humid', 'label' => 'Humid', 'type' => 'number')
),
'rows' => array()
);
while ($res = mysql_fetch_assoc($sth))
// array nesting is complex owing to to google charts api
array_push($data['rows'], array('c' => array(
array('v' => $res['TIME']),
array('v' => $res['TEMP']),
array('v' => $res['HUMID'])
)));
?>
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1.1', {'packages':['annotationchart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var bar_chart_data = new google.visualization.DataTable(<?php echo json_encode($data); ?>);
var options = {
title: 'Weather Station'
};
var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
chart.draw(bar_chart_data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>