Google 可视化 - AnnotatedTimeLine SQL

发布于 2024-11-13 10:07:15 字数 1891 浏览 3 评论 0原文

大家好,我想弄清楚这是如何运作的。我不知道为什么我总是得到一个空白页面

这是我的代码

来自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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失去的东西太少 2024-11-20 10:07:15

我以前遇到过这个问题。您需要将其更改

query.setQuery('select thedate,visits,sales from dothefetch');

为:

query.setQuery('select *');

这应该可行。如果没有,请尝试修复 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..

query.setQuery('select thedate,visits,sales from dothefetch');

.. to this:

query.setQuery('select *');

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文