Setting tick units.

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

Setting tick units.

Post by Erich Kilmer » Tue Feb 11, 2003 9:16 pm

From a previous post:
JFreeChart will then choose the smallest TickUnit in the collection such that the labels don't overlap.

This is is what I would like to do.

I started trying to set the tick units manually depending on the number of points or the amount of the date range (note this is on a time series chart). But I have had limited success. In one case where I was basing the tick units on the number of days in the range I had a situation where I had a graph with a single point with no dates on the date axis. Or if I was setting tick units based on the number of points I was running into situation where the date labels were overlapping and couldn't be read.

Can you show me a code snippet where you just let Jfreechart select the smallest tick unit that fits without overlapping date labels?

Thanks. Oh, my time series charts never have more than 30 points (a month's worth, 1 per day).

Erich Kilmer

Re: Setting tick units.

Post by Erich Kilmer » Tue Feb 11, 2003 9:43 pm

Tried adding: axis.createStandardDateTickUnits();
This does a nice job of placing the ticks near the points that are well spaced out but I do have some problems with the labels.

On a chart with only a single point the label at the bottom was a time (hh:mm:ss) instead of the date (mm/dd/yyyy) that I need.

On a chart with more points the ticks were nicely spaced out again but the labels at the bottom came out dd-mmm instead of the mm/dd/yyyy that I need.

Any advice how to fix these problems (meanwhile I will keep looking).

TIA

David Gilbert

Re: Setting tick units.

Post by David Gilbert » Tue Feb 11, 2003 11:40 pm

You have a few options:

1) Accept the default auto-selection of tick units, including formatting;

2) Leave auto-selection on, but create your own TickUnits collection...this allows you to define the formatting for each tick size. Look in the createStandardDateTickUnits method to see how a TickUnits collection is put together...you can create your own collection with any number of tick units;

3) Do 1) or 2), and also specify a formatter using the setDateFormatOverride method...tick units will be auto-selected, but the formatting will use the 'override' DateFormat object you specify.

4) Set a manual tick unit with it's own formatting...now there is no auto-selection. In this case, *you* are responsible for ensuring that the tick size is big enough that labels do not overlap.

Hope that helps,

Dave Gilbert

Locked