Google 可视化 - AnnotatedTimeLine SQL
大家好,我想弄清楚这是如何运作的。我不知道为什么我总是得到一个空白页面
这是我的代码
来自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();
?>
谁能告诉我我错过了什么?我总是进入空白页
hi everyone i am trying to figure out how this is going to work. i dont know why i am always getting a blank page
Heres my code
from the 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>
And from my 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();
?>
Can anyone tell me where did i miss out ? I am always getting into a blank page
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前遇到过这个问题。您需要将其更改
为:
这应该可行。如果没有,请尝试修复 preg_quote 问题:
https://code.google.com/p/ mc-goog-visualization/issues/detail?id=16
编辑: 与您的问题相同的问题可以在这里看到:Google Vis 使用 PHP JSON 从 SQL 数据库注释时间线问题
I have experienced this problem before. You need to change this..
.. to this:
This should work. If not, try to fix the preg_quote issue:
https://code.google.com/p/mc-goog-visualization/issues/detail?id=16
EDIT: The same problem as yours could be seen here: Google Vis annotated timeline from SQL database using PHP JSON issue