Google Charts addRows not accepting Dates when passed via parsed String

瀏覽次數:893 次
跳到第一則未讀訊息

Vincent Holland-Keen

未讀,
2016年10月10日 清晨6:10:522016/10/10
收件者:Google Visualization API
Hi,

I've been struggling for days to get dates working with a chart and have finally come to the (possibly erroneous) conclusion that there's a difference between the implementation of dates in the DataTable function and in the addRows function.

This JSFiddle hopefully shows what I mean: https://jsfiddle.net/fiskerton/vc4o0710/1/

If a DataTable is created with both columns and rows, passing in a JSON.parse'd string with a date value in the format 'Date(YYYY,MM,DD)' works fine. If that same format is passed to addRows, the console throws the error: 'Uncaught Error: Type mismatch. Value Date(YYYY,MM,DD) does not match type date in column index 1. I haven't found any other format that successfully takes a string containing a date and gets it to work with addRows - e.g. 'new Date(YYYY,MM,DD' fails with same error.

Is there something I've missed?

Thanks.

Daniel LaLiberte

未讀,
2016年10月13日 上午11:46:552016/10/13
收件者:Google Visualization API
Hi Vincent,

We have tried to unify the various ways of setting up DataTables, but there have been changes in how dates are handled recently, and it appears likely the case you found has been either broken, or always was broken.

Can you can use new Data(...) without quotes?  JSON notation doesn't allow new Date() constructors, so that is why the "Date(...)" format is supported at least there.  When you use JSON.parse() you are just turning the string into an anonymous JS object, so if you can use the anonymous JS object instead, with new Date() constructors, that would be the simplest workaround.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/6294cb99-9812-471b-87fc-7b040a6972c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Vincent Holland-Keen

未讀,
2016年11月2日 上午11:49:312016/11/2
收件者:Google Visualization API
Thanks for the suggestion. For the time being I've just passed the required rows into the DataTable initialisation. That doesn't allow me to add rows en masse later, but covered most of the situations I needed to handle. Unfortunately, I've since had to move on to other work, so haven't got time to back to this at the moment, but if the opportunity arises, I'll try the workaround above. 


On Thursday, October 13, 2016 at 4:46:55 PM UTC+1, Daniel LaLiberte wrote:
Hi Vincent,

We have tried to unify the various ways of setting up DataTables, but there have been changes in how dates are handled recently, and it appears likely the case you found has been either broken, or always was broken.

Can you can use new Data(...) without quotes?  JSON notation doesn't allow new Date() constructors, so that is why the "Date(...)" format is supported at least there.  When you use JSON.parse() you are just turning the string into an anonymous JS object, so if you can use the anonymous JS object instead, with new Date() constructors, that would be the simplest workaround.
On Mon, Oct 10, 2016 at 6:10 AM, Vincent Holland-Keen <vincen...@gmail.com> wrote:
Hi,

I've been struggling for days to get dates working with a chart and have finally come to the (possibly erroneous) conclusion that there's a difference between the implementation of dates in the DataTable function and in the addRows function.

This JSFiddle hopefully shows what I mean: https://jsfiddle.net/fiskerton/vc4o0710/1/

If a DataTable is created with both columns and rows, passing in a JSON.parse'd string with a date value in the format 'Date(YYYY,MM,DD)' works fine. If that same format is passed to addRows, the console throws the error: 'Uncaught Error: Type mismatch. Value Date(YYYY,MM,DD) does not match type date in column index 1. I haven't found any other format that successfully takes a string containing a date and gets it to work with addRows - e.g. 'new Date(YYYY,MM,DD' fails with same error.

Is there something I've missed?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.



--
回覆所有人
回覆作者
轉寄
0 則新訊息