Google Chart Date Format

I use Google Charts and try to create my own JSON format for chart rendering, not for using libraries. All is well, except that you are trying to figure out how to represent the date format in json, that the Google chart will understand ...

Spec: JSON does not support JavaScript Date values ​​(for example, "new Date (2008,1,28,0,31,26)", the implementation of the API does. However, the API now supports a custom JSON representation of dates as a string in the following format: Date ( year, month, day [, hour, minute, second [, millisecond]]), where everything the day after tomorrow is optional and the months are based on zero.

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

Reading the above specification would show that using the date format represented in json as Date (year, date, month) would work, but that doesn't work for me.

Error:

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

Json answer:

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

Nothing jumps at me, as this should fit the specified format. What am I missing?

+4
source share
1 answer

your syntax is wrong, I think ... you should try something like this:

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

for me this code worked:

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

but that means changing the month, not the day, and using json ....

+2
source

Source: https://habr.com/ru/post/1439278/


All Articles