Amna Ali
Amna Ali

Reputation: 1785

Highcharts date-format changes with data

I'm using Highcharts for creating a line graph. What I'm trying to do is to make sure that the Date Format on x-axis is in this format "%b %e". So, for example, 06/27/2014 is represented as Jun 17.

However, with the data that I have, even when I am setting the date-format right, highcharts would change it automatically in the chart.

In this jsfiddle http://jsfiddle.net/uw2j06gc/ you can see that just adding some data (by uncommenting some lines) is changing the date-format. Why?

    $(document).ready(function() {        
        $('#container').highcharts({
        xAxis: {
            type: 'datetime',
                    dateTimeLabelFormats: {
                        month: '%b %e'
                    }
                },
        credits: {
            enabled: false
        },
        series: [{
            data: [ 
           //if you uncomment the following 3 lines, the date format changes to Month-Day. Otherwise, it's Day-Month
           //         [Date.UTC(2014, 4, 27), 26],
           //         [Date.UTC(2014, 5, 3), 10],
           //         [Date.UTC(2014, 6, 27), 26],
                    [Date.UTC(2014, 7, 3), 10],
                    [Date.UTC(2014, 8, 27), 26],
                    [Date.UTC(2014, 9, 3), 10],
                    [Date.UTC(2014, 10, 9), 15],
                    [Date.UTC(2014, 11, 15), 40]
            ]
        }]
    });
});

Upvotes: 2

Views: 478

Answers (1)

Raein Hashemi
Raein Hashemi

Reputation: 3384

Because Highcharts dynamically sets the range of DateTime. If the data is within Week limit you should add:

week:'%b %e'

and for day:

day: '%b %e'

Add these and you will have your day, week and month range with '%b %e' format.

Upvotes: 2

Related Questions