如何更改Highcharts上的DateTime格式?

问题描述 投票:0回答:1

我在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 //
}]
});
});
javascript datetime highcharts datetime-format
1个回答
0
投票

使用此进行格式化

formatter: (currData) => {
     const currDate = new Date(currData.value);
     return currDate.getHours() + ':' + currDate.getMinutes();
},

小提琴-https://jsfiddle.net/5hupyv8m/1/

© www.soinside.com 2019 - 2024. All rights reserved.