Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HighCharts Date format

I have an application that returns JSON date to me which I display on a Highcharts bar graph. The field for the x-axis is a date and it comes back from the server is JSON format such as :"date":"2016-11-15T00:00:00.000Z"

I want to display the date on the x-axis as just 2016-11-15, or even better, display it in local date format, which in this case would be 2016-11-14 as it is GMT-5 hours.

I've read the documentation, but it doesn't seem to work. Any help is appreciated!!

like image 920
user2843365 Avatar asked Aug 09 '26 22:08

user2843365


1 Answers

You can parse ISO string date to js date with the Date constructor. And then get timestamp in milisecond - which is a required format for Highcharts.

new Date("2016-11-15T00:00:00.000Z").getTime(),

In the format property, you can define how the date should be displayed.

 xAxis: {
  type: 'datetime',
  labels: {
    format: '{value:%Y-%m-%d}',
  }
},

example: http://jsfiddle.net/akehpzq4/4/

For a local time, see useUTC option.

like image 138
morganfree Avatar answered Aug 11 '26 10:08

morganfree



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!