我在json上有日期时间数据,如下所示:“ timestamp”:“ 2020-03-15T11:46:10 + 07:00”。如何在高图上将日期格式更改为HH:mm?这是我的代码:https://jsfiddle.net/estri012/q89vt1j0/13/但似乎没有用。日期格式不会改变。
Highcharts.getJSON('https://gmlews.com/api/data', function (data) {
console.log(data);
var accelero_x = [], timestamp = [];
for (var i = 0; i < data.length; i++) {
accelero_x.push(data[i].accelero_x);
timestamp.push(data[i].timestamp);
}
console.log(accelero_x);
console.log(timestamp);
// Create the chart
var chart = new Highcharts.Chart({
chart: {
type: 'spline',
renderTo: 'container'
},
title: {
text: 'Coba'
},
tooltip: {
valueDecimals: 2
},
subtitle: {
text: 'Accelero X'
},
xAxis: {
type: "datetime",
categories: timestamp,
labels: {
format: '{value:%Y-%m-%d}',
rotation: 45,
align: 'left'
}
},
series: [{
data: accelero_x //
}]
});
});
使用此进行格式化
formatter: (currData) => {
const currDate = new Date(currData.value);
return currDate.getHours() + ':' + currDate.getMinutes();
},