chart.js-显示控件时标时区 [英] chart.js - display control timescale time zone

查看:38
本文介绍了chart.js-显示控件时标时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个图表配置为具有不同的时区(例如,我在utc + 00中,并且想要在utc + 01中显示数据)

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.

推荐答案

在时间配置选项中,将 parser 指定为函数:

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');
                            }                
                        }
                    }]

除了转换图表值外,这还将应用于x轴的最小值/最大值.

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');
}

这篇关于chart.js-显示控件时标时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆