1

highcharts x axis values showing wrong format.It show's default date and year like 1970-01-18 but my actual date is 23/02/2019, 00:43:08.i have seen many answers but i didn't solve my problem. JSfiddle link

"data": [{
      "x": 1550862788,
      "y": 526.4200000000001
    }, {
      "x": 1550862790,
      "y": 1850.3116666666667
    }, {
      "x": 1550862793,
      "y": 3199.786
    }]`
Vickey
  • 365
  • 1
  • 3
  • 17
G Crop
  • 11
  • 2

1 Answers1

2

You have passed the incorrect time in the x , current x value is 1550862788 if you passed this into to new Date(1550862788) you will get Mon Jan 19 1970 04:17:42 GMT+0530 (India Standard Time)

If you want 23/02/2019, 00:43:08 to be the starting x-axis value you need to pass 1550862788000 for now I have increment 1hr for each x-axis value.

Highcharts.setOptions({
    time: {
       useUTC: false
    }
});

$(function() {
  $('#container').highcharts({
 series: [{
  "name": "avg_sales",
  "color": "#3b6982",
  "data": [{
      "x": 1550862788000,
      "y": 526.4200000000001
    }, {
      "x": 1550866388000,
      "y": 1850.3116666666667
    }, {
      "x": 1550869988000,
      "y": 3199.786
    }]
}],
tooltip: {
  dateTimeLabelFormats: {
    hour: '%A, %b %e, %l %p'
  },
},
xAxis: {
  type: 'datetime',
  dateTimeLabelFormats: {
        millisecond: '%e. %b %I:%M %P',
        second: '%e. %b %I:%M %P',
        minute: '%e. %b %I:%M %P',
        hour: '%e. %b %I:%M %P',
        day: '%e. %b %I:%M %P',
        week: '%e. %b %I:%M %P',
        month: '%e. %b %I:%M %P',
        year: '%e. %b %I:%M %P'
    },
  },

 });
});

Updated Jsfiddle : https://jsfiddle.net/karnan796/veykdm7h/6/

To get the milliseconds for the current or specific date please make use of it currentmillis

Vickey
  • 365
  • 1
  • 3
  • 17
  • thanks @vickey for giving reply. but it is somehow fixing the issue but not sloved fully.when i check this value **1550862788** in **timestamp.online** it is showing exact date with time. as you suggest multiply the 1000 to current value and graph is plotted but some difference to server values not showing exact values.. is there any other solution – G Crop Feb 26 '19 at 06:33
  • hi @GCrop highcharts prefers to use milliseconds for the time-date intervals, so can you please check whether the server value is in timestamp or millisecond, also please have a look at this https://api.highcharts.com/highcharts/time.useUTC, if you are facing further issue please create a jsfiddle so i can figure it out – Vickey Feb 26 '19 at 06:43