我的工作从MySQL在图表上,它工作得很好的线型图,但是当我改变annotationchart它给了我下面的错误,由于它需要一个日期/时间,我改变了类型日期时间(为字符串),仍然有错误。
Type mismatch. Value 2014-07-23 19:03:16 does not match type datetime
原始代码
<?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>