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
Format tick units without setting divisions
Re: Format tick units without setting divisions
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.
Regards,
DG.
Re: Format tick units without setting divisions
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
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
Re: Format tick units without setting divisions
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.
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.