我在用 Highcharts 做一个折线图,想在 tooltip 里同时显示日期和数值,但默认只显示数值。试过用 tooltip.formatter,但不知道怎么拿到原始数据里的日期字段。
我的数据是这种格式:
series: [{
data: [
{ x: Date.UTC(2023, 0, 1), y: 29.9 },
{ x: Date.UTC(2023, 0, 2), y: 71.5 }
]
}]
怎么在 tooltip 里把日期格式化成 “2023-01-01: 29.9” 这样的字符串?
pre class="pure-highlightjs line-numbers">
tooltip: {formatter: function() {
return Highcharts.dateFormat('%Y-%m-%d', this.x) + ': ' + this.y;
}
}