Hi.
Sorry if I don't have the right terms here.
I have a bar chart, with a NumberAxis that displays the ticks for each int in my range.
The NumberAxis is displayed along the botton of the bar. Is it possible for it to be above displayed above the bar?
another question: is it possible to display a percent instead of a number, like 0% or 25%? The TickUnit takes a NumberFormatter object, and I don't see how I can use that to output a percent.
thanks!
Move rangeaxis to above the bar
Re: Move rangeaxis to above the bar
Hi Phillip,
At present the horizontal axis is fixed at the bottom of the plot, and the vertical axis is fixed at the left of the chart. I plan to change this to allow the position (top/bottom or left/right) to be specified, but haven't started any work on this yet.
You can set a percentage format using the DecimalFormat class (a subclass of NumberFormat):
NumberAxis axis = (NumberAxis)chartPlot.getRangeAxis();
axis.setTickUnit(new NumberTickUnit(0.1, new java.text.DecimalFormat("0.00%")));
This results in a fixed size tick unit. If you still require auto tick selection, then you need to create a TickUnits collection. Look in the TickUnits source code for examples of how these collections are constructed.
Regards,
DG.
Regards,
DG.
At present the horizontal axis is fixed at the bottom of the plot, and the vertical axis is fixed at the left of the chart. I plan to change this to allow the position (top/bottom or left/right) to be specified, but haven't started any work on this yet.
You can set a percentage format using the DecimalFormat class (a subclass of NumberFormat):
NumberAxis axis = (NumberAxis)chartPlot.getRangeAxis();
axis.setTickUnit(new NumberTickUnit(0.1, new java.text.DecimalFormat("0.00%")));
This results in a fixed size tick unit. If you still require auto tick selection, then you need to create a TickUnits collection. Look in the TickUnits source code for examples of how these collections are constructed.
Regards,
DG.
Regards,
DG.
Re: Move rangeaxis to above the bar
Hi David,
your
axis.setTickUnit(new NumberTickUnit(0.1, new java.text.DecimalFormat("0.00%")));
at first looks fine, but of course, like always
, customisation brings some trouble. I want to have a value axis in 10-percent steps: 10%, 20%, 30% and so on. Changing your example above to
axis.setTickUnit(new NumberTickUnit(10.0, new java.text.DecimalFormat("0%")));
gives 1000%, 2000%, 3000% ...
In the API there is written that the DecimalFormat containing "%" multiplies by 100 and sets the "%" behind. So I guess I have to avoid the multiplication by 100, but unfortunately I have no idea HOW. Might be trivial but it drives me crazy...
TIA,
Harald
your
axis.setTickUnit(new NumberTickUnit(0.1, new java.text.DecimalFormat("0.00%")));
at first looks fine, but of course, like always

axis.setTickUnit(new NumberTickUnit(10.0, new java.text.DecimalFormat("0%")));
gives 1000%, 2000%, 3000% ...
In the API there is written that the DecimalFormat containing "%" multiplies by 100 and sets the "%" behind. So I guess I have to avoid the multiplication by 100, but unfortunately I have no idea HOW. Might be trivial but it drives me crazy...
TIA,
Harald