gpt4 book ai didi

json - 谷歌图表json日期格式

转载 作者:行者123 更新时间:2023-12-04 08:55:43 25 4
gpt4 key购买 nike

我正在使用 Google Charts 并尝试生成我自己的 JSON 格式来呈现图表而不是使用库。除了试图弄清楚如何在 json 中表示谷歌图表可以理解的日期格式之外,一切都很好......

规范:
JSON 不支持 JavaScript 日期值(例如,“new Date(2008,1,28,0,31,26)”;API 实现支持。但是,API 现在支持将日期的自定义有效 JSON 表示形式为以下格式的字符串: Date(year, month, day[,hour, minute, second[, millisecond]]) 其中 day 之后的所有内容都是可选的,而月份是从零开始的。

引用:
https://developers.google.com/chart/interactive/docs/dev/implementing_data_source#jsondatatable

阅读上述规范似乎表明将 json 中的日期格式表示为 Date(year, date, month) 会起作用,但这似乎对我不起作用。

错误:

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"}}}}

没有什么是跳出来的,因为这应该遵循规范要求的格式。我错过了什么?

最佳答案

你的语法是错误的,我认为...
你应该尝试这样的事情:

{"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 ....

关于json - 谷歌图表json日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12850931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com