Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts: Dates Off By 1 Month

Tags:

highcharts

I'm not sure what's going on, but dates are being displayed on the axis and in tooltips a month out. So the first date in data on this chart is in July but it shows up as in August and so on. Any ideas? I've put the code in a JSFiddle (http://jsfiddle.net/Z2VGL/1/) and also below:

$(function () {
$('#container').highcharts({
    chart: {
        type: 'spline'
    },
    title: {
        text: ''
    },
    plotOptions: {
        series: {
            lineWidth: 5,
            marker: {
                fillColor: '#FFFFFF',
                lineWidth: 2,
                radius: 6,
                lineColor: null // inherit from series
            }
        }
    },
    subtitle: {
        text: ''
    },
    xAxis: {
        type: 'datetime',
        dateTimeLabelFormats: { // don't display the dummy year
            month: '%e %b',
            year: '%b'
        }
    },
    yAxis: {
        title: {
            text: 'Ability Score (out of 100)',
            style: {
                color: '#323A45',
                fontWeight: 'bold'
            }
        },
        min: 0
    },
    tooltip: {
        formatter: function () {
            return '<b>' + this.series.name + '</b><br/>' + Highcharts.dateFormat('%e %b', this.x) + ': ' + this.y;
        }
    },

    series: [{
        name: 'Overall Ability',
        // Define the data points. All series have a dummy year
        // of 1970/71 in order to be compared on the same x axis. Note
        // that in JavaScript, months start at 0 for January, 1 for February etc.
        data: [
            [Date.UTC(2013, 07, 12), 50],
            [Date.UTC(2013, 08, 13), 57.9474605576],
            [Date.UTC(2013, 08, 14), 58.5667571154],
            [Date.UTC(2013, 08, 15), 69.0590308869], ]

    }, {
        name: 'Target',
        data: [
            [Date.UTC(2013, 07, 12), 80],
            [Date.UTC(2013, 08, 13), 80],
            [Date.UTC(2013, 08, 14), 80],
            [Date.UTC(2013, 08, 15), 80],
            /*
                    [Date.UTC(2013,  0,  1), 80.0],
                    [Date.UTC(2013,  1,  1), 80.0],
                    [Date.UTC(2013,  2,  1), 80.0],
                    [Date.UTC(2013,  3,  1), 80.0],
                    [Date.UTC(2013,  4,  1), 80.0],
                    [Date.UTC(2013,  5,  1), 80.0],
                    [Date.UTC(2013,  6,  1), 80.0],
                    [Date.UTC(2013,  7,  1), 80.0]
                    */

], dashStyle: 'longdash', marker: { enabled: false } }]

});

});

Thanks in advance.

like image 939
user1149620 Avatar asked Aug 15 '13 16:08

user1149620


1 Answers

As you can see from this doc: Mozilla JS Reference Date UTC

month
An integer between 0 and 11 representing the month.
like image 168
Yura Beznos Avatar answered Nov 16 '22 02:11

Yura Beznos