You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/03/16 11:04:16 UTC

[GitHub] [echarts] throrin19 edited a comment on issue #14453: Possibility to set specific timezone for time axis

throrin19 edited a comment on issue #14453:
URL: https://github.com/apache/echarts/issues/14453#issuecomment-800163920


   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 : 
   
   ```js
   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]]),
       }],
   };
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org