【问题标题】:Google Visualization - AnnotatedTimeLine SQL谷歌可视化 - AnnotatedTimeLine SQL
【发布时间】: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


【解决方案1】:

我以前遇到过这个问题。你需要改变它..

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 annotated timeline from SQL database using PHP JSON issue

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    相关资源
    最近更新 更多