JoeTidee
JoeTidee

Reputation: 26044

How to offset HighCharts data?

I am using HighCharts (javascript chart plugin) and am generating a chart from a series of timestamps that are from the Europe/London timezone. When i feed these into HighCharts, they are converted to UTC. I have tried using:

global: {
    useUTC: false
}

but this has no effect. I am also trying to use momentJs like this:

global: {
    getTimezoneOffset: function (timestamp) {
        var destZone = 'Europe/London';
        var timezoneOffset = moment.tz(timestamp, destZone).utcOffset();
        return timezoneOffset;
    }
}

but agin, no effect. How can I acheive this?

Upvotes: 0

Views: 1375

Answers (2)

JoeTidee
JoeTidee

Reputation: 26044

I discovered that I was placing the global block

global: {
    ....
}

in the actual chart specific options. It actually needs to go into the Highcharts.setOptions block:

Highcharts.setOptions({
        global: {
            getTimezoneOffset: function (timestamp) {
                var chartTimezone = 'Europe/London';
                var timezoneOffset = -moment.tz(timestamp, chartTimezone).utcOffset();
                return timezoneOffset;
            }
        }
});

Upvotes: 4

Rafael Teles
Rafael Teles

Reputation: 2748

I had the same problem, solve it with:

global : {
    timezoneOffset: integerValue
}

The method is descrive in the api:

"The timezone offset in minutes. Positive values are west, negative values are east of UTC, as in the ECMAScript getTimezoneOffset method. Use this to display UTC based data in a predefined time zone. Defaults to 0."

In my case I'm using 180 (-03:00) as my integerValue

Upvotes: 0

Related Questions