drhanjuw56233 2013-03-28 01:13
浏览 23

谷歌图json php annotatedtimeline无法正常工作

I am having a problem with the google graph api.

The problem is that the Date not work in the annotatedtimeline graph. the graph is not visible. The data come from a MySQL database and that works fine. And it is a wordpress website. If a use a BarChart with int's instead of Date that is work fine.

The json Data:

{"cols":[{"label":"Datum","type":"string"},{"label":"Relax","type":"date"},
{"label":"Rest","type":"date"},{"label":"Active","type":"date"}],
"rows":[{"c":[{"v":"2013-03-27 17:05"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:53"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:53"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:51"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:41"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:38"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:32"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:31"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:31"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]},
{"c":[{"v":"2013-03-27 16:30"},{"v":"Date(2012, 12, 1)"},
{"v":"Date(2012, 12, 1)"},{"v":"Date(2012, 12, 1)"}]}]}

The php/html code this is one file.

$con = mysql_connect($db_host,$db_user,$db_pass) or die("Failed to connect with database!!!!");
mysql_select_db($db_db);

$sth = mysql_query("SELECT * FROM {$table}");

$rows = array();
//flag is not needed
$flag = true;
$table = array();
$table['cols'] = array(

    //Labels your chart, this represent the column title
    array('label' => 'Datum', 'type' => 'string'),
    array('label' => 'Relax', 'type' => 'date'),
    array('label' => 'Rest', 'type' => 'date'),
    array('label' => 'Active', 'type' => 'date')
);

$rows = array();
while($r = mysql_fetch_assoc($sth)) {
    $temp = array();
    // the following line will used to slice the Pie chart
    $temp[] = array('v' => (string) $r['Date']); 

    //Values of the each slice
    $temp[] = array('v' => "Date(2012, 12, 1)"); 
    $temp[] = array('v' => "Date(2012, 12, 1)");
    $temp[] = array('v' => "Date(2012, 12, 1)");

    $rows[] = array('c' => $temp);
}

$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
?>

  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">

    // Load the Visualization API and the piechart package.
    google.load('visualization', '1', {'packages':['annotatedtimeline']});

    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);

    function drawChart() {

      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(<?=$jsonTable?>);/*
      var options = {
            displayAnnotations: true,
            annotationsWidth: 20,
            scaleType: 'maximized'  
        };

      var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
      chart.draw(data, options);
      */
      var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));    
        chart.draw(data, 
            {
                displayAnnotations: true,
                annotationsWidth: 20,
                scaleType: 'maximized'      
            }
        );
    }
    </script>
  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>
  </body>

<?php include (TEMPLATEPATH . '/searchform.php'); ?>
</div>
<?php get_footer(); ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法