Sumedh
Sumedh

Reputation: 648

Display year in x axis of line graph highcharts

This is how the chart looks like at the moment:

http://jsfiddle.net/VunVq/1/

On the x axis instead displaying the full date, I just want to display year.

e.g 2008 2009 2010

The tooltip should display the full date though.

xAxis: {
            categories: ['2008-03-31', '2009-03-31', '2010-03-31']
        },

I read the api reference but cannot figure out how to display only year in x axis, maybe because its past my bedtime and my mind is not working.

Upvotes: 0

Views: 1243

Answers (2)

Sebastian Bochan
Sebastian Bochan

Reputation: 37588

You can also set type xaxis as datetime (http://api.highcharts.com/highcharts#xAxis.type) and use pointStart() / pointInterval for series.

Upvotes: 0

msapkal
msapkal

Reputation: 8346

Use the label's formatter callback JavaScript function to format the label.

 xAxis: {
            categories: ['2008-03-31', '2009-03-31', '2010-03-31'],
            labels: {
                formatter: function () {
                    return this.value.split('-')[0];
                }
            }
        }

DEMO

Upvotes: 1

Related Questions