Handling unix timestamp with highcharts

前端 未结 2 1617
盖世英雄少女心
盖世英雄少女心 2021-01-02 01:32

jsfiddle: http://jsfiddle.net/RjPRd/

Times & Labels are displayed incorrectly.

I think the timestamp should be multiplied by 1000 for Ja

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 02:26

    An easy way to work with timestamp (milliseconds) in Highcharts is use the formatter. So first receive your time values as unix timestamp and then set one of the features below in the chart:

    Using in xAxis labels:

    xAxis:[{
      labels:{
         formatter:function(){
             return Highcharts.dateFormat('%Y %M %d',this.value);
         }
      }
    }]
    

    Using in tooltip:

    tooltip: {
        readerFormat: {
            formatter: function(){
             return Highcharts.dateFormat('%Y %M %d',this.value);
         }
      },
        pointFormat: '{point.y} ms',
        shared: true
    },
    

    An exemple of code with tooltip

    A reference about formatter

提交回复
热议问题