Highcharts:如何在 xaxis 上只显示天数?

Highcharts : how to display only days on xaxis?

我正在使用 highstock 来显示我的数据。 x 轴上的刻度必须仅显示一周范围时间的天数。 我在这个例子中面临的问题 (see fiddle) 是第一个刻度显示小时数,我只想在 x 轴上显示天数而不显示小时数,有什么办法可以实现吗? 我将 startOnTick 属性设置为 true

xAxis: {
   startOnTick: true,
}

所以现在图表以一天开始,但第一个刻度仍然是一个小时值有没有办法将第一个刻度移动到图表原点 (0,0) 坐标?

设置格式为毫秒是不够的。在API中我们可以读到:

For a datetime axis, the scale will automatically adjust to the appropriate unit. This member gives the default string representations used for each unit. For intermediate values, different units may be used, for example the day unit can be used on midnight and hour unit be used for intermediate values on the same axis.

您需要为更多单位定义 dateTimeLabelFormats 或对标签使用 formatter 函数。

xAxis: {
  ...,
  dateTimeLabelFormats: {
    millisecond: '%b %e',
    second: '%b %e',
    minute: '%b %e',
    hour: '%b %e',
    day: '%b %e',
    week: '%b %e',
    month: '%b %e',
    year: '%b %e'
  }
}

现场演示: https://jsfiddle.net/BlackLabel/5r1v8tLo/

API参考:

https://api.highcharts.com/highcharts/xAxis.dateTimeLabelFormats

https://api.highcharts.com/highcharts/xAxis.labels.formatter