Timelines not lining up

22 views
Skip to first unread message

stephen...@trinsic.co

unread,
Mar 24, 2016, 5:53:16 AM3/24/16
to Google Visualization API
I am trying to create a timeline chart in which multiple blocks are on the same line, butted against each.

However it is splitting them apart although it is keeping them in the same grouping row. The strange thing is when I change the date format it results in them lining up as I want them to.

I've a fiddle here in which you can see both cases https://jsfiddle.net/bj46bxL9/

The problem is the date format that works is 'new Date(yyyy, mm, dd) ' which uses zero based months and my data isn't zero based so the date format I'm using new Date('yyyy-mm-dd') displays the correct date but seems to cause the blocks to not line up.

Does anyone know why they are splitting and how can I stop it from happening. 

Thanks

Sergey Grabkovsky

unread,
Mar 24, 2016, 10:04:52 AM3/24/16
to Google Visualization API
Hi Stephen,

It looks like the Date constructor isn't parsing your dates properly. Experimenting with it in the console, I found that:
new Date(2016, 5, 2) results in the date "Thu Jun 02 2016 00:00:00 GMT-0400 (EDT)"
new Date('2016-06-02') results in the date "Wed Jun 01 2016 20:00:00 GMT-0400 (EDT)"

Note that this is a very different date than what we expected. Experimenting with it a bit more, it appears that the following works properly:
new Date('06-02-2016') results in the date "Thu Jun 02 2016 00:00:00 GMT-0400 (EDT)"

So it appears that the date constructor doesn't understand strings in the form "yyyy-mm-dd", but in "mm-dd-yyyy". This probably differs based on locale as well. If I were you, I would not use such an error-prone method to construct my dates. If your dates come in that form, it would be best for you to parse them yourself (or use another library like date.js) and hand the components to the Date constructor so that there is no room for confusion.

--
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-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@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/e4b35b6d-c394-49eb-ab38-9c861b495245%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

unnamed.gif

Sergey Grabkovsky

Software Engineer

Google, Inc

gra...@google.com


Reply all
Reply to author
Forward
0 new messages