question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possibility to set specific timezone for time axis

See original GitHub issue

What problem does this feature solve?

In our case, we have many clients arround the world. We want have the ability to show their data using their timezone. Actually, Echarts use GMT dates to set xAxis intervals labels and current browser timezone for date format.

We correctly set the correct timezone in formatter but, for intervals, we have already the problem of GMT.

It’s a really important feature for us.

What does the proposed API look like?

An option, in xAxis to set timezone should be great to fix the problem :

xAxis : {
    type : 'time',
    timezone : 'Europe/Paris',  // with that, all xAxis times are manipulated using this timestamp
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

3reactions
throrin19commented, Mar 16, 2021

I found how to resolve this with date-fns-tz :

I force the dateTime in UTC but converted in specific timezone using function utcToZonedTime. And with that, all showed dates are correctly showed in specific timezone without any problems :

import { utcToZonedTime, format } from 'date-fns-tz';

const timezone = 'America/Boise';
const time = [
    1615868012847,
    1615889612847,
];

const data = [
    // data array with [time, value] items
];

const options = {
    xAxis   : {
        type        : 'time',
        min         : utcToZonedTime(time[0], timezone),
        max         : utcToZonedTime(time[1], timezone),
    },
    tooltip : {
        trigger     : 'axis',
        confine     : true,
        axisPointer : {
            animation   : false,
            label       : {
                formatter({ value }) {
                    // used to already show datetime completelly
                   return format(value, 'yyyy-MM-dd HH:mm:ss', { timeZone : timezone });
                },
            },
        },
    },
    series : [{
        type : 'line',
        name : 'test',
        data : data.map(item => [utcToZonedTime(item[0], timezone) ,item[1]]),
    }],
};
1reaction
ptuloucommented, Oct 15, 2021

We are also looking for something like this. We allow users to set the time zone they want to see and that time zone may be different from the browser’s time. We’re passing in ISO strings for the times and it seems whether I pass in UTC, or specific time zones echarts always (correctly) converts them to the browser’s time zone. We tried to work around this by leaving off the time zone information which mostly works except it does not handle the transition to/from DST as one might expect.

What we would like would be a way to set a time zone for the whole chart, or perhaps per series. All times passed into the data would be displayed and calculated in that time zone rather than the browser’s time zone.

Our fallback solution in the interim is to continue to pass in UTC times and override every tooltip and axis formatter to convert to the time zone the user specified to make it appear like the data is in the right time zone. The only draw back to this approach that I’ve found is that the axis ticks that are chosen are not nice round times like there would normally be (i.e. it chooses to put a tick at what appears to be 3 am instead of midnight).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possibility to set specific timezone for time axis
Hello Everyone, I have an important question/feature asking for Echarts. In our case, we have to works with many timezones to show our...
Read more >
Time axis in d3.js with specific time zone - Stack Overflow
Now comes the requirement to show it in a specific time zone (say, 'Asia/Calcutta'). Is there a way to achieve this? The max...
Read more >
OJ-Chart: time axis values always displayed adjusted to the ...
Is there a way to display those time values in the horizontal axis adjusted to a specific given timezone?
Read more >
Timezone in JavaScript Schedule control - Syncfusion
Apart from the default action of applying specific timezone to the Scheduler, it is also possible to set different time zone values for...
Read more >
time.timezone | highcharts API Reference
Since v6.0.5, the time options were moved from the global obect to the time object, and time options can be set on each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found