有没有一种标准的方法可以在Highcharts上获得x轴上的日期? 我在他们的文档中找不到相关信息:https://api.highcharts.com/highcharts/xAxis.type
当我的时间范围足够大时,它会显示日期。 但是,当时间范围不够大时,它只会显示小时,如下图所示:
这不是很理想... 如果此情况下能够显示日期和时间,那就太好了。 有人知道怎么做吗?
如果x轴的类型是 'datetime'
,Highcharts将自动尝试找到当前缩放范围的最佳格式。然后计算当前缩放的单位,可以是以下之一:
然后使用此单位查找轴标签的格式。默认格式如下:
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
如果您希望日期成为“小时”级别标签的一部分,您应该更改该级别的dateTimeLabelFormats
选项,包含%d
或%e
。以下是可用的格式:http://api.highcharts.com/highcharts#xAxis.dateTimeLabelFormats
请查看来自Highcharts API的示例.
替换这个
return Highcharts.dateFormat('%a %d %b', this.value);
使用此功能
return Highcharts.dateFormat('%a %d %b %H:%M:%S', this.value);
查看这里关于dateFormat()
函数的内容。
同时还请参见 - tickInterval和pointInterval
dateFormat
接受的日期代码列表:https://github.com/highcharts/highcharts/issues/6737#issuecomment-303073344 - Trevor Gehman你可以这样写:
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
day: '%d %b %Y' //ex- 01 Jan 2016
}
}
还要检查其他的日期时间格式。
http://api.highcharts.com/highcharts#xAxis.dateTimeLabelFormats