Annotated Timeline rangechange date/timezone shift

268 views
Skip to first unread message

Bob

unread,
Dec 19, 2011, 5:39:55 PM12/19/11
to Google Visualization API
Hi,

I'm currently working on an app that is using the annotated timeline
chart. We added a listener for the rangechange event, which seems to
work, but the start and end dates returned by the chart seem a little
strange. For instance, when I zoom the chart to November 3rd as the
start date, the listener (chartname.getVisibleChartRange.start)
reports November 1st (plus an hh:mm:ss component). Sometimes the
start date is right on, sometimes it is off by one or two days. I'm
executing some ajax to return data based on the timeline zoom, so a
day or two difference can result in a completely different dataset.

I understand that timezones come into play here (I'm in CST... -5 or 6
depending on daylight savings), but I'm not sure why the dates are off
by up to 2 days. To test this, I went to the google code playground
and added a listener to the sample:

Sample url: http://code.google.com/apis/ajax/playground/?type=visualization#annotated_time_line

Listener I added:

google.visualization.events.addListener(annotatedtimeline,
'rangechange', function(){
console.log('Start: ' +
annotatedtimeline.getVisibleChartRange().start);
});

You can observe the same date behavior on this playground that I see
locally: I chose Feb 3rd - Feb 6th (specifically, the first point
where the legend (at the top of the chart) showed Feb 3rd as the start
point). I expected to see Feb 3rd with some time component but
instead saw Fri Feb 01 2008 12:22:39 GMT-0600 (Central Standard
Time). This seems like a bug. Am I missing something?

asgallant

unread,
Dec 19, 2011, 5:56:26 PM12/19/11
to google-visua...@googlegroups.com
I tried it out and it works just fine for me.

Bob

unread,
Dec 20, 2011, 10:27:55 AM12/20/11
to Google Visualization API
Thanks for checking it out, but I'm confused. After adding the
listener and then selecting Feb 3rd (by using the legend date of Feb
3rd, not aligning the slider under the x-axis marker for Feb 3rd) the
console logs Feb 3rd? Every single time I do this I get Feb 1st
logged in the console, no exceptions. I can get on or near Feb 3rd
reported in the console if I line up the zoom slider with the x-axis
marker for Feb 3rd, but in real life this would be impractical,
considering our charts have 6-12 months of data listed.

Is this a timezone issue? I can't see how, considering I'm CST, which
is - 5/6 hours; that doesn't resolve the (sometimes) 36 hour
discrepancy I'm seeing put into the console. Again, I wonder if I'm
missing something or being a bit thick?

Thanks

Bob

asgallant

unread,
Dec 20, 2011, 10:59:58 AM12/20/11
to google-visua...@googlegroups.com
As far as I can tell, the legend dates go noon to noon, rather than midnight to midnight (so Feb 3 is from 12:00 Feb 2 - 11:59 Feb 3).  Why this is so, I cannot say.  The start and end points of the range are exact values, however, and are logged correctly, see http://jsfiddle.net/mgHdu/

Bob

unread,
Dec 20, 2011, 12:43:08 PM12/20/11
to Google Visualization API
Me again. :)

I actually see the same behavior in your example on fiddle as in the
google code playground (and our site). I think my point isn't coming
across correctly; when I say the date legend, I'm talking about the
range of dates that appears at the very top of the graph, next to the
text that reads: "Sold Pencils {some number}" and "Sold Pens {some
number}". If you watch that date range when sliding the zoom control,
and use that to pick Feb 3rd (as our users do), the date that is
logged (for us) is Feb 01. Our users are using that legend to select
an appropriate range for a graph that shows 1 year's worth of data.
Aligning the zoom control under the x-axis is pretty inaccurate when
you're dealing with 6 mo - 1 year worth of data.

Here are some screenshots to illustrate:

What I've chosen, with the text of the legend: http://f.imgtmp.com/HLc16.png
What is output in console: http://f.imgtmp.com/FHltz.png

Thanks

Bob

asgallant

unread,
Dec 20, 2011, 1:42:02 PM12/20/11
to google-visua...@googlegroups.com
That's bizarre - I could have sworn that when I built that this morning, the legend was behaving differently.  It looks like the range is always <first full day in range> to <last partial day in range>, where days are determined noon-to-noon.  At 12:00:01 on Feb 2, the date legend advances to Feb 3; this is why you can be off by up to 36 hours.

I would call this bugged in two ways:
1) days should be demarcated midnight-to-midnight
2) when changing the range, the legend should show the days the range starts and ends in
Reply all
Reply to author
Forward
0 new messages