且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google时间轴和一系列日期

更新时间:2023-08-17 18:06:04

您需要输入日期作为日期对象。最简单的方法是对数据使用DataTable JSON结构:

You need to input the dates as date objects. The easiest way to do that is to use the DataTable JSON structure for your data:

$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中:

then in javascript:

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