Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

formatting labels by timezone in a datetime axis #42

Open
GoogleCodeExporter opened this issue Mar 10, 2015 · 6 comments
Open

formatting labels by timezone in a datetime axis #42

GoogleCodeExporter opened this issue Mar 10, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

1.  Create a DataTable:

myDataTable = DataTable.create();
myDataTable.addColumn(ColumnType.DATETIME);
myDataTable.addColumn(ColumnType.NUMBER);

2.  Add bunch of rows:

myDataTable.setValue(recCount, 0, myDate);
myDataTable.setValue(recCount, 1, myFloat);

Each java.util.Date instance is constructed from a unix datetime long value 
retrieved from a database.  In this example there are 24 datapoints retrieved, 
each pair separated by one hour, beginning at 0000 UTC and running through 2300 
UTC (inclusive) on the day in question.

3.  Use DateFormat to format the first column of the completed DataTable:

// this works correctly!
DateFormatOptions utcFmtOptions = DateFormatOptions.create();
utcFmtOptions.setTimeZone(0);
utcFmtOptions.setPattern("yyyy-MM-dd HH:mm:ss z");
DateFormat utcFmt = DateFormat.create(utcFmtOptions);
utcFmt.format(dataTable, 0);

4.  Create a LineChart (this code snippet is somewhat abridged):

LineChart myChart = new LineChart();
LineChartOptions options = LineChartOptions.create();
options.setBackgroundColor("#f0f0f0");
options.setLineWidth(2);
HAxis xAxis = HAxis.create(xLabel);
// this is a PROBLEM -- displays in Browser/Client local time zone
xAxis.setFormat("MM/dd HH:mm");
options.setHAxis(xAxis);
VAxis yAxis = VAxis.create(yLabel);
yAxis.setViewWindowMode("maximized");
options.setVAxis(yAxis);
myChart.draw(dataTable, options);

What is the expected output? What do you see instead?

See two attached screen caps showing two views of the resulting chart.  This is 
a particularly obvious example because it covers Sunday, March 10, 2013, which 
is when my local browser/client timezone begins daylight saving.  The records 
are retrieved correctly in unix datetimes for that day, exactly one hour apart, 
and the xAxis title (which I constructed) is correctly showing UTC.  The hover 
text of every individual datapoint is also correct.  But the xAxis labels are 
showing not in UTC but some in EST and some in EDT (note the irregular grid 
spacing, too).

In the first image the hover text is correctly showing a time of 0100 UTC but 
that spot on the axis is labeled with 2000 (EST) the day before, five hours 
off.  In the second image the hover text is correctly showing a time of 1600 
UTC but that spot on the axis is labeled with 1200 (EDT), which is four hours 
off.

I would like some way of specifying not just a format mask but also a timezone 
for the axis labels.  Or perhaps some way of setting a global default timezone 
that would override the browser/client locale.  These data are all collected, 
stored, and published in UTC and there is no reason anyone would ever want to 
view them in their local time zone.

What operating system, browser and version are you using?

I'm not sure which details are relevant here (and I'd be happy to provide more) 
but here are some:

Server:  Scientific Linux 6.4, 2.6.32-358.11.1.el6.i686
Client:  Mac OS X 10.8.4, Safari 6.0.5 (8536.30.1)

regards,
Mike J+

Original issue reported on code.google.com by n...@jankplus.users.panix.com on 16 Jul 2013 at 10:30

Attachments:

@galmok
Copy link

galmok commented Jan 19, 2017

I have pretty much the same problem. I try to have the x-axis show date in UTC format, but it isn't possible to set the timezone on the x-axis (or any axis for that matter). This means if you have data in UTC timezone, e.g. "2017-01-19T09:00:00Z", you can have a formatter use "{ pattern: "yyyy-MM-dd HH:mm:ss 'UTC'", timeZone: 0 }" and have the popup show the correct timestamp "2017-01-19 09:00:00 UTC", but on the hAxis, you can only set the format, not the timezone. This means all dates on the hAxis are converted to local time and at best, you can have it attach the timezone like this: format: 'yyyy-MM-dd HH:mm:ss Z'. The result would be (in Denmark, UTC+1 in the winter): 2017-01-19 10:00:00 +0100. While technical correct, this isn't what I want (I want UTC timezone).

Currently, the only solution seems to be to convert the original timestamp to localtime this way: "2017-01-19T09:00:00Z" -> "2017-01-19 09:00:00". This would help, but still be wrong during the daylight saving time switches.

Or manually handle the hAxis ticks and labels, i.e. reinvent the algorithm to select ticks and then put on the correct labels.

@liangde-chen
Copy link

Vote for same issue.

@prabal77
Copy link

same issue. Voting for this.

@codefocus
Copy link

Running into this as well.

Data is shown in two timezones: The correct one (configured to EST) in the hover text, and the incorrect one (browser timezone) on the hAxis tick labels.

@jonmitten
Copy link

Same issue here. Vote for this as well. hAxis should have timezone specification support.

@gorghino
Copy link

Same, even if I'm not hopeful. No commits since 2016..

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants