2014-09-05 187 views
0

我正在创建一个数组,并且我的日期和国家一起(它从我的数据库中出来)。如何基于这些数据创建我的AnnotatedTimeLine?我得到的错误“一栏必须包含日期或日期和时间”与我的当前设置Google时间轴和日期列表

创建数组

while($r = mysqli_fetch_assoc($sth)) { 
$callDate = strtotime($r[CALLDATEEST]); 
$convertedCallDate = date("Y-m-d",$callDate); 
$pieChartArray .= "[$convertedCallDate, '$r[COUNTRY]'],\n"; 
} 
$pieChartArray = substr(trim($pieChartArray), 0, -1); 
?> 

功能

var data = google.visualization.arrayToDataTable([ 
      ['Call times', 'Country'], 
      <?php echo $pieChartArray; ?> 
      ]); 

回答

1

您需要输入的日期为日期对象。要做到这一点,最简单的方法是使用你的数据在数据表JSON结构:

$data = array(
    'cols' => array(
     array('type' => 'date', 'label' => 'Call times'), 
     array('type' => 'number', 'label' => 'Country') 
    ), 
    'rows' => array() 
); 
while($r = mysqli_fetch_assoc($sth)) { 
    $callDate = strtotime($r[CALLDATEEST]); 
    $year = (int) date("Y",$callDate); 
    $month = ((int) date("m",$callDate)) - 1; // convert months to javascript's 0-indexed months 
    $day = (int) date("d",$callDate); 

    $data['rows'][] = array('c' => array(
     array('v' => "Date($year, $month, $day)"), 
     array('v' => $r[COUNTRY]) 
    )); 
} 

然后在javascript:

var data = new google.visualization.DataTable(<?php echo json_encode($data, JSON_NUMERIC_CHECK); ?>); 
+0

嗨,我是不是不太熟悉parseInt函数,我得到一个错误调用未定义的函数parseInt() – EricSSH 2014-09-05 23:44:21