Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts - Display only year in x axis and stop auto formatting

Tags:

highcharts

This is how the chart looks like at the moment:

http://jsfiddle.net/YWLpr/2/

enter image description here

If you see the x axis, you can see Month as well as Year while I want to display just the year.

Surprisingly if you add one more data entry in the series

 [Date.UTC(2011,2,31), 11.30] 

The x axis auto formats itself and display only the year

e.g. - http://jsfiddle.net/YWLpr/3/

So if there are 7 data points I can see year in the x axis but if there are less than 7 data points I can see month and year which is not what I want. How can I stop this auto formatting and display only the year in x axis for less than 7 data points.

like image 461
Sumedh Avatar asked Mar 24 '23 03:03

Sumedh


2 Answers

If you resize the chart the zoomlevel will switch from year to month therefor you'll have to add a formatting option for month too:

        dateTimeLabelFormats: {
            month: '%Y',
            year: '%Y'
        }
like image 97
dgw Avatar answered Apr 09 '23 20:04

dgw


You can always use label.formatter or label.format, see: http://jsfiddle.net/PwEnd/14/

Docs: http://api.highcharts.com/highcharts#xAxis.labels.format

like image 40
Paweł Fus Avatar answered Apr 09 '23 21:04

Paweł Fus