谷歌时间线图表连接到PHP mysql

时间:2014-03-23 10:31:45

标签: php charts

现在我的时间线图表在我的网页中根本没有显示我不确定我的代码有什么问题没有给我任何错误。

我认为这可能与我设定的日期格式有关,但我不确定。我仔细检查了日期格式,我正在使用它与我的数据库匹配。

如果你能指出错误的地方,我将不胜感激。 谢谢

<?php
$sth = "SELECT * FROM goal WHERE account_id =$account_id";
$result4 = mysqli_query($con,$sth) or die(mysqli_error());
$rows = array();
$flag = true;
$table = array();
$table['cols'] = array(
  array('type' => 'string', 'label' => 'goalName'),
    array('type' => 'date', 'label' => 'starts'),
    array('type' => 'date', 'label' => 'finish'));

//$rows = array();
while($rows = mysqli_fetch_assoc($result4)) {
$temp = array();
$starts = date("Y-m-d"); 
$finish = date("Y-m-d"); 

$temp[] = array('v' => (string) $rows['goalName']); 
$temp[] = array('v' => (string) $rows['starts']); 
$temp[] = array('v' => (string) $rows['finish']); 
$rows[] = array('c' => $temp);}

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


<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':    [{'name':'visualization',
   'version':'1','packages':['timeline']}]}"></script>
<script type="text/javascript">

google.setOnLoadCallback(drawChart);
function drawChart() {

var container = document.getElementById('example3.1');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
var data = "" google.visualization.DataTable(<?php echo json_encode($table,  JSON_NUMERIC_CHECK); ?>);

var options = {
    title: 'Progress',
    is3D: true
var options = {
timeline: { colorByRowLabel: true }
};

chart.draw(dataTable, options);
}

</script>

1 个答案:

答案 0 :(得分:0)

朋友详细信息在var选项中被解释两次,因此您看到:

var options = {

    title: 'Progress',
    is3D: true
var options = {

timeline: { colorByRowLabel: true }

};

时应如下所示
var options = {

    title: 'Progress',
    is3D: true,
     timeline: { colorByRowLabel: true }
};

我希望它能帮到你