score:42

Accepted answer

internally highcharts uses javascript date numbers (the number of milliseconds since jan 1st 1970) to represent dates. see mozilla reference.

to get dates on an axis you will first need to set the axis type to 'datetime':

xaxis: {
    type: 'datetime'
}

you have a few options when specifying the series data (all three examples produce the same chart):

  1. setting a start point and using a fixed interval between points

    pointstart: date.utc(2012, 2, 6, 10),
    pointinterval: 1000 * 60 * 60,
    data: [5, 6, 4]
    
  2. specifying the exact date using the date.utc method. this way its readable for humans:

    data: [
        [date.utc(2012, 2, 6, 10), 5], 
        [date.utc(2012, 2, 6, 11), 6], 
        [date.utc(2012, 2, 6, 12), 4]]
    
  3. or specifying the epoch time directly:

    [[1331028000000, 5], [1331031600000, 6], [1331035200000, 4]]
    

example on jsfiddle

score:4

adding to @eolsson, epoch time is usually the way to go since technically, date() objects are javascript, not json, and you're unlikely to find an off-the-shelf serializer that generates them.

you'll want to format the date, too, something like this --

xaxis: {
  type: 'datetime',
  labels: {
    formatter: function() {
      return highcharts.dateformat('%e %b', this.value*1000); // milliseconds not seconds
    },
  }
}

the date formatting is done php style.


Related Query

More Query from same tag