Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 谷歌时间表和一系列日期_Php_Google Visualization - Fatal编程技术网

Php 谷歌时间表和一系列日期

Php 谷歌时间表和一系列日期,php,google-visualization,Php,Google Visualization,我正在创建一个数组,我有日期和国家(它来自我的数据库)。如何基于此数据创建带注释的Timeline?我在当前设置中遇到错误“第一列必须包含日期或日期和时间” 创建数组 while($r = mysqli_fetch_assoc($sth)) { $callDate = strtotime($r[CALLDATEEST]); $convertedCallDate = date("Y-m-d",$callDate); $pieChartArray .= "[$convertedCallDate, '

我正在创建一个数组,我有日期和国家(它来自我的数据库)。如何基于此数据创建带注释的Timeline?我在当前设置中遇到错误“第一列必须包含日期或日期和时间”

创建数组

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; ?>
            ]);
var data=google.visualization.arrayToDataTable([
[‘通话时间’、‘国家’],
]);

您需要将日期作为日期对象输入。最简单的方法是对数据使用DataTable 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); ?>);
var data=new google.visualization.DataTable();

Hi,我对parseInt不太熟悉,对未定义函数parseInt()的调用出错