【发布时间】:2014-01-24 12:28:14
【问题描述】:
大家好,我想弄清楚这是如何工作的。我不知道为什么我总是得到一个空白页
这是我的代码
来自 index.html
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["annotatedtimeline"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
//Tell Google Visualization where your script is
var query = new google.visualization.Query('/vis.php');
query.setQuery('select thedate,visits,sales from dothefetch');
query.send(function(result) {
if(result.isError()) {
alert(result.getDetailedMessage());
} else {
var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
chart.draw(result.getDataTable(), {'colors': ['green', 'blue'], displayAnnotations: true, 'zoomStartTime': new Date(2011, 3 ,1), 'zoomEndTime': new Date(2011, 3 ,2) });
}
});
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
而且来自我的 vis.php
<?php
require_once 'lib/MC/Google/Visualization.php';
$user = 'root';
$db = new PDO('mysql:host=localhost;dbname=mywebsite',$user,'');
$vis = new MC_Google_Visualization($db,'mysql');
/*
foreach($db->query('SELECT * from total') as $row) {
print_r($row);
}
*/
$vis->addEntity('dothefetch', array(
'fields' => array(
'thedate' => array('field' => 'thedate', 'type' => 'datetime'),
'visits' => array('field' => 'visits', 'type' => 'number'),
'sales' => array('field' => 'sales', 'type' => 'number')
)
));
$vis->setDefaultEntity('dothefetch');
$vis->handleRequest();
?>
谁能告诉我我错过了哪里?我总是进入一个空白页
【问题讨论】:
-
这和 App Engine 没有任何关系吧?
-
你确定你的数据库返回了什么?你试过只打印结果吗?它们长什么样?另外,如果你只是转储 result.getDataTable() 会被转储什么?
标签: visualization data-visualization google-visualization