2

I use ZingChart to show data as a chart. In the char, I show the data following a time which I get from the server. ZingChart is set as default to follow client time.

I found we can set time zone in a chart only as integer value. However, some time zone are UTC+10:30, UTC+04:30...

So how can we set time zone to ZingChart showing correct time? And if that day has Daylight Saving Time, how should I correct it.

JSON scripts

Merrily
  • 1,686
  • 10
  • 14
Tri Pham
  • 91
  • 10
  • Would you be able to show the json and javascript of how you are configuring your chart? Are you using ZingChart to handle the querying from your server using the `refresh` property or are you handling that separately? – mike-schultz Nov 30 '15 at 16:37
  • Thanks for your attention! – Tri Pham Dec 01 '15 at 01:49
  • In my sence, the server in UTC +1: windhoek and the client in UTC +7:Ha Noi and Daylight Saving Time began... Belows are JSON script: "graphset":[ { "scale-x":{ "max-labels":7, "zooming":true, "min-value":1445884200000, "step":3600000, "transform":{ "type":"date", "all":"%M %d,%Y
    %h:%i %A", "guide":{ "visible":false }, "item":{ "visible":false } } }, }
    – Tri Pham Dec 01 '15 at 02:09
  • @mike-schultz please see my answer below. Thanks. – Matt Johnson-Pint Dec 01 '15 at 05:49

2 Answers2

5

Unfortunately it appears that ZingChart only supports whole-hour time zone offsets. Not only does this not account for time zones with fixed fractional-hour offsets, but it also doesn't properly account for time zones that use daylight saving time.

The example in the documentation says:

... For example, to set the timezone to Pacific Time, you would add: "timezone":-8.

This is incorrect, as Pacific time is only at UTC-8 during standard time. When it's in daylight time, it uses UTC-7.

This is a common mistake. See "Time Zone != Offset" in the timezone tag wiki. My recommendation to the ZingChart developers would be:

  1. Anywhere you support timezone:-8 you should also support fractional hour offsets such as timezone:5.5 or timezone:8.75.

  2. You should also support named time zone identifiers such as "America/Los_Angeles". To make them work, you'll need to provide a function that the developer can hook into. Don't try to implement the function directly, as there are several libraries already available for this. For example, a developer might combine ZingChart with moment-timezone by writing something like:

    zingchart.fnTZOffset = function(timestamp, timeZone) {
        return moment(timestamp).tz(timeZone).utcOffset() / 60;
    }
    

    ZingChart would invoke this function when timezone was a string and would apply the resulting offset to the specific data point.

Without support from ZingChart, there's not much you can do to properly support time zones.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Thanks for your answer! I think you right but unfortunately, ZingChart only support hour offsets as integer. I used expression: (local - utctime) / 3600 to get timezone. But if It has daylight saving time, I will have trouble. While C++ not support get timezone. – Tri Pham Dec 01 '15 at 06:56
  • 1
    Thanks Matt, we'll definitely work on supporting fractional hours and come up with an easier way to support time zones so it's easier for end-users. – mike-schultz Dec 01 '15 at 16:09
0

One other solution to the Daylight Savings time issue some ZingChart users have mentioned in the past is MomentJS. http://momentjs.com

Merrily
  • 1,686
  • 10
  • 14