Control date tick formatting on X-axis

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

Control date tick formatting on X-axis

Post by Keith Iosso » Thu Jan 11, 2001 4:45 pm

Greetings,
Thanks again for the great tool. I am using the TimeSeries to plot data over a one or two day period. The default tick label formatting is relatively wide and when combined with the size of my graph provides only a few ticks. When I dateAxis.setVerticalTickLabels(true) the ticks have only the time and no date.
I want to set the tick formatting, but I can't figure out how. The following code seems to have no effect, whether the setVerticalTickLabels is true or false. Please help

HorizontalDateAxis dateAxis =
(HorizontalDateAxis)myPlot.getHorizontalAxis();
dateAxis.setVerticalTickLabels(true);
dateAxis.getTickLabelFormatter().applyLocalizedPattern("M/dd/yy H");

TIA,
Keith

David Gilbert

RE: Control date tick formatting on X-axis

Post by David Gilbert » Sun Jan 14, 2001 7:52 pm

Hi Keith,

I think your code would work if the autoTickUnits attribute was set to false, but then you would have to choose the tick size that is appropriate.

If you want to leave JFreeChart to choose the tick size, but still want to control the date formatting, go to the end of the DateAxis.java source file and amend the standardTickUnits and standardTickFormats arrays. There should be a one-to-one correspondence between the values in the two arrays and they should be in size order, but otherwise it should cause no problems if you change the values, insert new values or delete existing values.

I chose the default values to give reasonable results for the charts I produce...but didn't spend lots of time thinking about it. So if there are better default values then let me know and I'll change the source.

Regards,

DG.

Locked