问题
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