Highcharts 在工具提示中使用本地日期而不是 utc 日期
Highcharts use loal date instead of utc date in tooltip
我正在使用 Highcharts,我希望工具提示内容显示如下:local date : value
(而不是默认格式 categorie name : value
)所以我使用 tooltip.formatter
是这样的:
tooltip: {
formatter() {
return `${Highcharts.dateFormat('%H:%M:%S', +new Date(this.x))}: <b>
${new Intl.NumberFormat().format(this.y)}</b>`
}
}
现在的问题是,我在 x 轴上显示本地日期,现在工具提示上的日期是 utc 日期,但我希望它也是本地日期:see jsfiddle.
我无法使用 global.useUTC,因为它自 v6.0.5 以来已被弃用。
有什么方法可以使日期与 xaxis 上的日期完全一致,以便工具提示显示:date : value
(如果我不必在 Highcharts.dateFormat
中使用 Highcharts.dateFormat
会更好=13=] 因为格式并不总是 '%H:%M:%S'
并且它会随提供的数据而变化) ?
使用图表时间格式化工具提示:
// Store a reference to the chart
const stockChart = Highcharts.stockChart('container', {
// ...
tooltip: {
formatter() {
// Use the time object of the chart to format the date
return `${stockChart.time.dateFormat('%H:%M:%S', +new Date(this.x))}: <b>${new Intl.NumberFormat().format(this.y)}</b>`
}
}
// ...
})
我正在使用 Highcharts,我希望工具提示内容显示如下:local date : value
(而不是默认格式 categorie name : value
)所以我使用 tooltip.formatter
是这样的:
tooltip: {
formatter() {
return `${Highcharts.dateFormat('%H:%M:%S', +new Date(this.x))}: <b>
${new Intl.NumberFormat().format(this.y)}</b>`
}
}
现在的问题是,我在 x 轴上显示本地日期,现在工具提示上的日期是 utc 日期,但我希望它也是本地日期:see jsfiddle.
我无法使用 global.useUTC,因为它自 v6.0.5 以来已被弃用。
有什么方法可以使日期与 xaxis 上的日期完全一致,以便工具提示显示:date : value
(如果我不必在 Highcharts.dateFormat
中使用 Highcharts.dateFormat
会更好=13=] 因为格式并不总是 '%H:%M:%S'
并且它会随提供的数据而变化) ?
使用图表时间格式化工具提示:
// Store a reference to the chart
const stockChart = Highcharts.stockChart('container', {
// ...
tooltip: {
formatter() {
// Use the time object of the chart to format the date
return `${stockChart.time.dateFormat('%H:%M:%S', +new Date(this.x))}: <b>${new Intl.NumberFormat().format(this.y)}</b>`
}
}
// ...
})