Format tick units without setting divisions

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

Format tick units without setting divisions

Post by Belinda » Tue Oct 22, 2002 11:15 am

Is it possible to set the format of the y-axis tick unit, without actually having to manually set divisions, i.e.:

yAxis.setTickUnit(new NumberTickUnit(divisions, new DecimalFormat("#")));


but using the default divisions that JFreechart would work out for me?


Many thanks,
Belinda Haughton

Dave Gilbert

Re: Format tick units without setting divisions

Post by Dave Gilbert » Tue Oct 22, 2002 4:58 pm

At the moment, the best you can do is create your own TickUnits collection, and then call the setStandardTickUnits(...) method in the NumberAxis class. Take a look at how it is done in the createStandardTickUnits(...) method in the NumberAxis class...you can create your own collection using whatever formatting object(s) you want.

Regards,

DG.

Belinda

Re: Format tick units without setting divisions

Post by Belinda » Wed Oct 23, 2002 2:51 pm

Hi David

Thanks for getting back to me.

I am struggling to get this to work. When I create a TickUnits collection, I need to add TickUnit objects to it. I am using NumberTickUnit. This requires a double value and a format. The format is obviously the one I want to use (eg. #.##), but the double value is for the amount of ticks.

This is what I am doing, but whilst the formatting is now correct, it is putting a tick in for every value

TickUnits tu = new TickUnits();
double d = 1.0;
tu.add(new NumberTickUnit(d, new DecimalFormat("#.##")));
yAxis.setStandardTickUnits(tu);

I do not want to calculate the number of tick units - but this way I am forced to put one in. I have looked in the TickUnits class at how the standard tick units are created
( units.add(new NumberTickUnit(new Double(0.0000001), new DecimalFormat("0.0000000")));
units.add(new NumberTickUnit(new Double(0.000001), new DecimalFormat("0.000000"))); etc...)

but I am unsure exactly what it is doing. And I am unsure what values I should put in my TickUnits collection so that tick units are calculated automatically.
All I want is to control the format - but I am struggling to find a way. Any help would be greatly appreciated!

Regards,
Belinda

Dave Gilbert

Re: Format tick units without setting divisions

Post by Dave Gilbert » Wed Oct 23, 2002 5:53 pm

Hi Belinda,

The TickUnits collection should contain a whole range of different tick sizes, and JFreeChart will choose the smallest one such that the labels don't overlap. If you only put one NumberTickUnit in the collection, then that is the one that gets selected every time.

A different solution for you might be to add an "override format" to the NumberAxis class. If this NumberFormat object is null, then the existing formatter is used, but if it is not null then the formatting is overridden. Would that help?

Regards,

DG.

Locked