如何从多个数组为Google Timeline创建正确的数组

时间:2017-10-02 17:52:35

标签: php arrays

我一直试图弄清楚如何为谷歌创建合适的数组 时间表图表,如高级示例:

https://developers.google.com/chart/interactive/docs/gallery/timeline#an-advanced-example

我有一个函数可以执行查询并返回所需的数组,但单独返回代码:

$data0 = array();
$data1 = array();

$array = array();
$array[] = array("v" => $name . ' ' . $id);
$array[] = array("v" => (string) 'Process 1');
$array[] = array("v" => (string) $date1);
$array[] = array("v" => (string) $date2);
$data0[] = array("c" => $array);

$array = array();
$array[] = array("v" => $name . ' ' . $id);
$array[] = array("v" => (string) 'Process 2');
$array[] = array("v" => (string) $date3);
$array[] = array("v" => (string) $date4);
$data1[] = array("c" => $array);

return $data0;
//return array($data0,$data1) 
// array merge did not work for me in this scenario

对于图形我遍历一个返回多个值的查询结果,我需要从每个值中检索几个日期:

while ($rows = mysqli_fetch_object($query)) {

list($data0,$data1) = ep_timeline($dbcon, $rows->id, $periodo);
$temp[] = $data0;
//$temp[] = $data0+$data1; <-- not work

}


$table['rows'] = $temp;
$jsonTable = json_encode($table);

如果我只使用一个数组,则图表有效。 $ data0,但我需要从两个数组创建一个单独的数组,例如$ data0数组是这样的:

Array
(
[c] => Array
    (
        [0] => Array
            (
                [v] => Proyect 1
            )

        [1] => Array
            (
                [v] => Process 1
            )

        [2] => Array
            (
                [v] => Date(2017,7,11)
            )

        [3] => Array
            (
                [v] => Date(2017,7,14)
            )

    )

)

和$ data1如下所示:

Array
(
[c] => Array
    (
        [0] => Array
            (
                [v] => Proyect 1
            )

        [1] => Array
            (
                [v] => Process 2
            )

        [2] => Array
            (
                [v] => Date(2017,7,14)
            )

        [3] => Array
            (
                [v] => Date(2017,7,24)
            )

    )

)

最终数组应如下所示:

Array
(
[c] => Array
    (
        [0] => Array
            (
                [v] => Proyect 1
            )

        [1] => Array
            (
                [v] => Process 1
            )

        [2] => Array
            (
                [v] => Date(2017,7,11)
            )

        [3] => Array
            (
                [v] => Date(2017,7,14)
            )

    )

)    
Array
(
[c] => Array
    (
        [0] => Array
            (
                [v] => Proyect 1
            )

        [1] => Array
            (
                [v] => Process 2
            )

        [2] => Array
            (
                [v] => Date(2017,7,14)
            )

        [3] => Array
            (
                [v] => Date(2017,7,24)
            )

    )

)

但我找不到创造它的方法,任何灯光都会受到赞赏

此致

0 个答案:

没有答案