Alvaro
Alvaro

Reputation: 41605

Display JavaScript Date in X axis in hightcharts

I have a series consisting of a pair X,Y values. X being a Javascript Date.

When displaying the graph I can't see in the X any reference to those date values. How can I display them in the X axys as well as in the tooltips?

Reproduction online

    $('#container').highcharts({
        xAxis: {
            type: 'datetime',
            minPadding: 0.05,
            maxPadding: 0.05
        },

        series: [{
            data: [
                [new Date(2016,08,28), 29.9],
                [new Date(2016,09,28), 71.5],
                [new Date(2016,10,28), 106.4]
            ]
        }]
    });

Upvotes: 0

Views: 19

Answers (1)

jlbriggs
jlbriggs

Reputation: 17800

You need to use the Date.UTC method.

You can just update this:

[new Date(2016,08,28), 29.9]

To

[Date.UTC(2016,08,28), 29.9]

Updated fiddle:

(keep in mind, month numbers start at 0 in javascript, not 1, so adjust accordingly)

Upvotes: 1

Related Questions