Google Chart将日期更改转换为一个月后的日期

时间:2018-02-13 20:34:55

标签: javascript php date google-visualization

我最近在谷歌图表上苦苦挣扎,将我的PHP代码转换为JSON,并被谷歌图表Javascript模块所接受。通过这种方式,我的意思是转换很好,它可以工作,但不知何故,当我将我的值作为日期传递一个月后的数据。因此,不是2017.10.24,我的最后数据是2017.11.24,但具有相同的值。我怀疑转换日期时会有什么东西,因为当我将它们作为字符串值传递时,它们会被正确传递。

传递为日期值:

{
    "cols":[
        {"type":"date","label":"Date","p":{}},
        {"type":"number","label":"Column2"}],
    "rows":[
        {"c":[{"v":"2017-11-16T23:00:00.000Z"}, {"v":null}]},
        {"c":[{"v":"2017-10-25T22:00:00.000Z"},{"v":12071}]},
        {"c":[{"v":"2017-10-26T22:00:00.000Z"},{"v":12071}]},
        {"c":[{"v":"2017-10-27T22:00:00.000Z"},{"v":12071}]},
        {"c":[{"v":"2017-10-28T22:00:00.000Z"},{"v":12071}]},
        {"c":[{"v":"2017-10-29T23:00:00.000Z"},{"v":12071}]},
        {"c":[{"v":"2017-10-31T23:00:00.000Z"},{"v":12071}]},
        {"c":[{"v":"2017-11-01T23:00:00.000Z"},{"v":12071}]},
        {"c":[{"v":"2017-11-02T23:00:00.000Z"},{"v":10371}]},
        {"c":[{"v":"2017-11-03T23:00:00.000Z"},{"v":10371}]},
        {"c":[{"v":"2017-11-04T23:00:00.000Z"},{"v":10371}]},
        {"c":[{"v":"2017-11-05T23:00:00.000Z"},{"v":10371}]},
        {"c":[{"v":"2017-11-06T23:00:00.000Z"},{"v":10371}]},
        {"c":[{"v":"2017-11-07T23:00:00.000Z"},{"v":10371}]},
        {"c":[{"v":"2017-11-08T23:00:00.000Z"},{"v":10371}]},
        {"c":[{"v":"2017-11-09T23:00:00.000Z"},{"v":10215}]},
        {"c":[{"v":"2017-11-10T23:00:00.000Z"},{"v":10215}]},
        {"c":[{"v":"2017-11-11T23:00:00.000Z"},{"v":10215}]},
        {"c":[{"v":"2017-11-12T23:00:00.000Z"},{"v":10215}]},
        {"c":[{"v":"2017-11-13T23:00:00.000Z"},{"v":10215}]},
        {"c":[{"v":"2017-11-14T23:00:00.000Z"},{"v":10215}]},
        {"c":[{"v":"2017-11-15T23:00:00.000Z"},{"v":10215}]},
        {"c":[{"v":"2017-11-16T23:00:00.000Z"},{"v":12501}]},
        {"c":[{"v":"2017-11-17T23:00:00.000Z"},{"v":12501}]},
        {"c":[{"v":"2017-11-18T23:00:00.000Z"},{"v":12501}]},
        {"c":[{"v":"2017-11-19T23:00:00.000Z"},{"v":12501}]},
        {"c":[{"v":"2017-11-20T23:00:00.000Z"},{"v":12501}]},
        {"c":[{"v":"2017-11-21T23:00:00.000Z"},{"v":12501}]},
        {"c":[{"v":"2017-11-22T23:00:00.000Z"},{"v":12501}]}
    ]}
}

传递为字符串值:

{
    "cols":[
        {"type":"string","label":"Date","p":{}},
        {"type":"number","label":"Columns2"}],
    "rows":[
    {"c":[{"v":"Date(2017,10,17)"},{"v":null}]},
    {"c":[{"v":"Date(2017,09,26)"},{"v":12071}]},
    {"c":[{"v":"Date(2017,09,27)"},{"v":12071}]},
    {"c":[{"v":"Date(2017,09,28)"},{"v":12071}]},
    {"c":[{"v":"Date(2017,09,29)"},{"v":12071}]},
    {"c":[{"v":"Date(2017,09,30)"},{"v":12071}]},
    {"c":[{"v":"Date(2017,10,01)"},{"v":12071}]},
    {"c":[{"v":"Date(2017,10,02)"},{"v":12071}]},
    {"c":[{"v":"Date(2017,10,03)"},{"v":10371}]},
    {"c":[{"v":"Date(2017,10,04)"},{"v":10371}]},
    {"c":[{"v":"Date(2017,10,05)"},{"v":10371}]},
    {"c":[{"v":"Date(2017,10,06)"},{"v":10371}]},
    {"c":[{"v":"Date(2017,10,07)"},{"v":10371}]},
    {"c":[{"v":"Date(2017,10,08)"},{"v":10371}]},
    {"c":[{"v":"Date(2017,10,09)"},{"v":10371}]},
    {"c":[{"v":"Date(2017,10,10)"},{"v":10215}]},
    {"c":[{"v":"Date(2017,10,11)"},{"v":10215}]},
    {"c":[{"v":"Date(2017,10,12)"},{"v":10215}]},
    {"c":[{"v":"Date(2017,10,13)"},{"v":10215}]},
    {"c":[{"v":"Date(2017,10,14)"},{"v":10215}]},
    {"c":[{"v":"Date(2017,10,15)"},{"v":10215}]},
    {"c":[{"v":"Date(2017,10,16)"},{"v":10215}]},
    {"c":[{"v":"Date(2017,10,17)"},{"v":12501}]},
    {"c":[{"v":"Date(2017,10,18)"},{"v":12501}]},
    {"c":[{"v":"Date(2017,10,19)"},{"v":12501}]},
    {"c":[{"v":"Date(2017,10,20)"},{"v":12501}]},
    {"c":[{"v":"Date(2017,10,21)"},{"v":12501}]},
    {"c":[{"v":"Date(2017,10,22)"},{"v":12501}]},
    {"c":[{"v":"Date(2017,10,23)"},{"v":12501}]}
    ]
}

我分配如下的值:

for ($i=$weeks; $i > 0; $i--) {
    $date1 = new DateTime($arraySomething[$i]["date"]);

    $dataArray['rows'][] = array(
        'c' => array (
            array('v' => "Date(".$date1->format("Y,m,d").")"), 
            array('v' => $arraySomething[$i]["property"])
        )
    );

}

有没有人知道为什么会这样?另外,我的第一个价值在某种程度上是另一个值,因为脚本的另一部分,但是不要介意。

提前致谢!

0 个答案:

没有答案