如何为日期时间刻度格式化 x 标签

How to format x labels for a datetime scale

我有这个图表https://playground.anychart.com/D7okDBpO/4

据我所知,x 标签会根据 anychart.format.outputDateFormat() 自动格式化,因此格式化它们的唯一方法是调用 anychart.format.outputDateFormat("someformat")。问题是我在一个页面上有多个图表,它们都需要不同的格式,从多个图表更改这个全局设置会导致并发问题(在某些图表上,x 标签被格式化为多种不同的格式)。

有没有其他方法来格式化它们?从 x 标签的格式化函数访问原始数据就足够了,但它不存在:

chart.xAxis().labels().format(function () {
    console.log(this); // only contains the already formatted date
    return this.value;
});

this.tickValue 包含未格式化的日期,因此您可以使用 {%tickValue} 和 {%x} 字符串标记分别格式化轴标签和工具提示。请检查此 sample,注意第 35-36 行。