Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timezone on Highcharts

As far as I understand the default for Highcharts is to UTC. I have tried to do as suggested by the answer in this post Highcharts graph X-axis label for different date ranges. If I understand correctly this should set the timezone to be that of the browser.

I've tested this on jsFiddle and toggling the useUTC option seems to have no effect.

http://jsfiddle.net/looneyp/me3ry/

Question: What am I doing wrong above and how do you set the time zone correctly?

like image 398
Codey McCodeface Avatar asked Aug 21 '12 10:08

Codey McCodeface


5 Answers

Highcharts have moved this option in more recent versions.

One thing to keep in mind is that your shift seems to be the inverse or negative of where your local time from UTC, so if you're in UTC+2 for example, then your timezoneOffset is going to be -2 * 60, which is not entirely intuitive:

Highcharts.setOptions({
    time: {
        timezoneOffset: -2 * 60
   }
});

API documentation: https://api.highcharts.com/highcharts/time.getTimezoneOffset

Here is an example of it: http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/time/timezoneoffset/

like image 159
Allan Houston Avatar answered Oct 03 '22 02:10

Allan Houston


Add this code to the document.ready and you should get the highcharts in your local timezone if you're feeding it UTC time

$(document).ready(function () {

  Highcharts.setOptions({
      global: {
          /**
           * Use moment-timezone.js to return the timezone offset for individual
           * timestamps, used in the X axis labels and the tooltip header.
           */
          getTimezoneOffset: function (timestamp) {
              d = new Date();
              timezoneOffset =  d.getTimezoneOffset()

              return timezoneOffset;
          }
      }
  });

});
like image 36
veritas Avatar answered Oct 03 '22 02:10

veritas


It's one of those days

I'm in the UK so UTC true or false gives the same results since I am in GMT. My discrepancy between my expected displayed time was due to a parsing issue in PHP to unixTime.

like image 11
Codey McCodeface Avatar answered Nov 16 '22 04:11

Codey McCodeface


Highcharts now supports timezones in 3.0.8

You can now set the timezoneOffset global property: http://api.highcharts.com/highcharts#global.timezoneOffset

like image 7
magagnon Avatar answered Nov 16 '22 06:11

magagnon


Nothing you are doing seems to be wrong. This jsFiddle shows a shift in the x-axis when UTC is disabled in the global Highcharts options.

like image 6
Dennis Avatar answered Nov 16 '22 06:11

Dennis