2012-10-12 100 views
4

我正在使用Google Charts並嘗試生成自己的JSON格式來呈現圖表,而不是使用庫。除了試圖弄清楚如何在json中表示日期格式以便Google圖表能夠理解...Google Charts json日期格式

規範: JSON不支持JavaScript日期值(例如「new Date(2008,1 ,28,0,31,26)「; API實現的確如此,但API現在支持以日期(年,月,日[,小時,分鐘,第二[,毫秒]),這裏的一切一天之後是可選的,月是零基礎

參考: https://developers.google.com/chart/interactive/docs/dev/implementing_data_source#jsondatatable

看完上面的規格似乎秈稻以日期格式(日期,年份,日期,月份)表示的日期格式可以工作,但這似乎不適用於我。

錯誤:

Uncaught Error: Type mismatch. Value Date(2012, 10, 3) does not match type date in column index 0 

JSON響應:我

{"type":"ComboChart","cols":[["date","Date"],["number","Overall"],["number","Current"],["number","Rating Count"]],"rows":[["Date(2012, 10, 3)",4.0,4.0,69],["Date(2012, 10, 4)",4.0,4.0,69]],"options":{"title":"Rating for FI","chartArea":{"width":"90%","height":"75%"},"hAxis":{"title":"Date"},"legend":"top","curveType":"none","pointSize":8,"seriesType":"bars","series":{"0":{"type":"bars","targetAxisIndex":0},"2":{"type":"line","targetAxisIndex":1}},"vAxes":{"0":{"title":"Rating","minValue":0,"maxValue":5},"1":{"title":"Rating Count"}}}} 

沒有什麼是跳出來,因爲這應遵循規範所要求的格式。我錯過了什麼?

回答

2

你的語法是錯誤的,我認爲...... 你應該嘗試類似的東西:

{"type":"ComboChart","cols":[["date","Date"],["number","Overall"],["number","Current"],["number","Rating Count"]],"rows":[["Date(2012, 10, 3)"]],["Date(2012, 10, 4)"]],"options":{"title":"Rating for FI","chartArea":{"width":"90%","height":"75%"},"hAxis":{"title":"Date"},"legend":"top","curveType":"none","pointSize":8,"seriesType":"bars","series":{"0":{"type":"bars","targetAxisIndex":0},"2":{"type":"line","targetAxisIndex":1}},"vAxes":{"0":{"title":"Rating","minValue":0,"maxValue":5},"1":{"title":"Rating Count"}}}} 

對我來說,這個代碼工作:

{"c":[{"v":"Date(2012,11)"},{"v":6657}..... 

但這是更改月份,不是一天和使用JSON ....