Date labels on the x axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Belinda Haughton

Date labels on the x axis

Post by Belinda Haughton » Fri Mar 22, 2002 11:38 am

Hi

I am using a HorizontalDateAxis for my xAxis. I would like to control the frequency of tick labels and have used the following code:

xAxis.setAutoTickUnitSelection(false);
xAxis.setTickUnit(new DateUnit(Calendar.YEAR, 1));

This would set a label every year.

However, the labels look weird. Instead of coming out 1998, 1997 as they would if I used the Default JFreeChart labelling, they display the full day including time. I haven't been able to find a method to change the date format. (I.e. using SimpleDateFormat).

Could you please let me know how I can control the frequency as well as the format of the date labels?

Thanks in advance,
Belinda

bjm

Re: Date labels on the x axis

Post by bjm » Mon Mar 25, 2002 1:21 pm

Hi!

I do something like this - it seems to work...

axis.setAutoTickUnitSelection(false);
axis.setTickUnit(new DateUnit(Calendar.MONTH,1));
SimpleDateFormat sdf = axis.getTickLabelFormatter();
sdf.applyPattern("dd-MM-yy");

Locked