Squishy Squishy - 1 month ago 11x
Javascript Question

Highcharts: set regular intervals on xaxis

I have a series of data values over time (determined by a count). Data is provided at n minute intervals (count x interval); typically the data will be 96 x 15 (96 15minute intervals to give 24 hours). The length of the intervals and the count are both dynamic. The data series can be numerous types of data; it could be in numerous formats like 0.000123 or 1.23 or 198763.0000089675.

I would like my xaxis to show time in 1 hour intervals (screen real estate is small, so 2 hour intervals might be whats needed). I have this:

xAxis: {
type : 'datetime',
title: {
text: 'Time ('+period+')'
dateTimeLabelFormats: {
minute: '%H:%M',
hour: '%H:%M'

and a series like this:


but the values on the xaxis are:

00:00:00.020 00:00:00.040 00:00:00.020 00:00:00.020

I've poked through the highcharts API but I can't make head nor tails of how it deals with timeseries.

How can I tell highcharts to display the time correctly?


If the axis is of type datetime then the chart will render them the best way it sees fit. If you don't like the way they are rendered, you can control the datetime formats of the chart using dateTimeLabelFormats like you are already doing.

Based on the datetime span of the data at the time the chart will pick one of the following default formats:

second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'

If you want to force them all to the Hour and Minute no matter what the range is then set them as follows:

second: '%H:%M',
minute: '%H:%M',
hour: '%H:%M',
day: '%H:%M',
week: '%H:%M',
month: '%H:%M',
year: '%H:%M'

To control the interval of the dates shown use tickInterval. Since your axis is of type datetime you will have to use milliseconds as the unit for your tickInterval. So, a 1 hour tickinterval in milliseconds is 3600000. If you want it to be 2 hours then use 7200000.