axis labels

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

axis labels

Post by Mike » Wed Dec 11, 2002 8:13 pm

Greetings,


Is there a way to label tick marks with a standard value instead of the tick marks labeled according to the data.

For example:

The X data is in the range 0 to 270
The Y data is in the range -10 to 23

The desired labels would be something like this.

X Axis Labels : 0, 10, 20 , 30, 40, 50 ....... 270
Y axis labels : -10, -5, 0, 5, 10 , 20, 23

There may be tick marks in between but the optimal situation is that those tick marks would not be labeled.


Thanks

Mike

David Gilbert

Re: axis labels

Post by David Gilbert » Wed Dec 11, 2002 11:32 pm

Hi Mike,

At the moment, ticks and labels go together in JFreeChart. The spacing between the tick units is chosen from a default collection of "standard" tick units, in such a way that the labels don't overlap but there are still as many ticks as possible (within the available space).

The default collection (from which a single tick unit is chosen at the time the chart is drawn) is created in the createStandardTickUnits() method in the NumberAxis class. This is the way that JFreeChart ensures that the tick units are multiples of 10, or 25, or 50, or 100, and so on.

But you don't have to use the default collection, you can create your own and register it with the axis via the setStandardTickUnits(...) method.

Alternatively, you can create a single NumberTickUnit instance, and then call the setTickUnit(...) method on the axis...but watch out if the chart is resized, the labels might start overlapping.

Regards,

DG

Mike

Re: axis labels

Post by Mike » Fri Dec 13, 2002 3:23 pm

So if I create a collection using the example mentioned previously, I will get tick marks only at 0,10, 20 , 30 etc? I always want the ending label to be the last data value.

Thanks,

MJ

Locked