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 approach? Also I believe the setup is still incorrect because the labels seem opposite to where the cursor is.



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/


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:

         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


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.