chart.js - display control timescale time zone

谁说胖子不能爱 提交于 2021-02-18 13:06:10

问题


I want to configure one chart to have a different timezone (for example I'm in utc+00 and want to display data in utc+01)

Is there a way? according to docs I have to return a moment object, and then date displays according to moment global locale.


回答1:


In the time configuration options specify parser as a function:

                scales: {
                    xAxes: [{
                        type: 'time',
                        time: {
                            unit: 'hour',
                            min: minDate,
                            max: maxDate,
                            displayFormats: {
                                hour: 'HH'
                            },
                            parser: function (utcMoment) {
                                return utcMoment.utcOffset('+0100');
                            }                
                        }
                    }]

As well as converting the chart values this will also apply to the min/max values of the x axis.

This assumes your min/max values and label array is populated with moment objects. If dealing with date objects then the function needs to convert the date to a moment first.

parser: function(date) {
    return moment(date).utcOffset('+0100');
}


来源:https://stackoverflow.com/questions/40891462/chart-js-display-control-timescale-time-zone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!