Highchart:在午夜显示时间和日期
问题描述:
我有一张显示我测量的最后x个数据点的高图。 这可能是几天或几个小时。Highchart:在午夜显示时间和日期
当我有几个小时的时候,我想显示“HH:mm”。当它是午夜时,我想显示“HH:mm DD.MM.JJJJ”。
但是,当我显示了几天我只是想显示“DD.MM.JJJJ”
答
我找到了一个解决方案:
formatter: function() {
if (this.axis.tickPositions.length > 2 && (this.axis.tickPositions[1] - this.axis.tickPositions[0]) < (24 * 3600 * 1000)) {
if (this.dateTimeLabelFormat == format_days) {
this.dateTimeLabelFormat = format_minutes + "<br />" + format_days;
}
}
return this.axis.defaultLabelFormatter.call(this);
但我敢肯定有一个更好的解决方案。
答
您可以将dateTimeLabelFormats
对象更改为在特定单位上显示特定日期格式。
API参考:
http://api.highcharts.com/highcharts/xAxis.dateTimeLabelFormats
,但我要为一天两个不同的格式:1,如果只显示天,如果一个显示时间(以及在午夜天) –