HighCharts在xAxis上显示日期时间格式 [英] HighCharts show datetime format on xAxis
问题描述
我试图在高图表的x轴上以日/周/月格式显示dateTime我将数据格式化为x utc日期时间格式和y(幅度)。我的印象是我只需要这样做就可以了。
I am trying to display dateTime in day/weekly/month format on the x axis of high charts I have the data formatted as x utc date time format and y (magnitude). I was under the impression I only need to do this for it to work
Highcharts.chart('container', {
title: {
text: 'Chart with time'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
day: "%e. %b",
month: "%b '%y",
year: "%Y"
}
},
series: [{
data: [
[1493326164493, 100],
[1493326194018, 120]
]
}]
});
我做错了什么?我已经为我的方案发布了一个小提琴链接
What am I doing wrong? I have posted a fiddle link below for my scenario
https:/ /jsfiddle.net/dLfv2sbd/
推荐答案
axis.dateTimeLabelFormats 的工作方式略有不同。首先,Highcharts试图猜测数据的最佳单位是什么,例如如果是一天,它将根据dateTimeLabelFormats的day属性对其进行格式化。
axis.dateTimeLabelFormats works a little bit different. In the first place, Highcharts tries to guess what is 'the best unit' of your data and, e.g. if it is a day, it will format it according to day property from dateTimeLabelFormats.
如果您只想格式化轴标签,可以使用 axis.labels.format 并指定如下格式:
If you want to just format axis labels, you can use axis.labels.format and specify a format like this:
xAxis: {
type: 'datetime',
labels: {
format: '{value:%Y-%b-%e}'
},
示例: https://jsfiddle.net/dLfv2sbd/1/
这篇关于HighCharts在xAxis上显示日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!