highcharts timestamp转换为人类可读的日期时间

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

我有附加的高图,时间戳显示为从DB收到。我需要以某种方式将其转换为人类可读,但没有成功。 highchart

      xAxis: {
    type: 'datetime',
    categories: labels,
    formatter: function () {
      return "mydate: " + moment.utc(moment.unix(this.x/1000)).format("DD/MM-YYYY HH:mm:ss") + "<br> myspeed: " + this.y;
    }
  }
highcharts
1个回答
0
投票

formatter选项必须嵌套在labels中,而不是嵌套在xAxis中:https://api.highcharts.com/highcharts/xAxis.labels.formatter

xAxis: {
    type: 'datetime',
    categories: labels,
    labels: {
        formatter: function () {
            return "mydate: " + moment.utc(moment.unix(this.x/1000)).format("DD/MM-YYYY HH:mm:ss") + "<br> myspeed: " + this.y;
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.