Handling unix timestamp with highcharts

前端 未结 2 1596
盖世英雄少女心
盖世英雄少女心 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:03

    You are right, timestamps in Javascript are milliseconds so you should multiply everything by 1000.

    For the other problem it comes from the fact that your data is ordered backwards. Apparently HighCharts is messing up when the series are not properly ordered.

    Here's the correction for your code: http://jsfiddle.net/cvedovini/RjPRd/2/

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题