Skip to content Skip to sidebar Skip to footer

Handling Unix Timestamp With Highcharts

jsfiddle: http://jsfiddle.net/RjPRd/ Times & Labels are displayed incorrectly. I think the timestamp should be multiplied by 1000 for Javascript Time but what's the best approa

Solution 1:

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/

Solution 2:

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(){
         returnHighcharts.dateFormat('%Y %M %d',this.value);
     }
  }
}]

Using in tooltip:

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

An exemple of code with tooltip

A reference about formatter

Post a Comment for "Handling Unix Timestamp With Highcharts"