1

In JFreeChart, I am using the setRenderAsPercentage(true) option for StackedBarRenderer . Although the plot itself looks fine (all bars span the whole plot), the range axis labels are not showing percent values (i.e. 0 to 100) but probabilities (i.e. 0 to 1).

How can I achieve percentage values?

rainer198
  • 3,195
  • 2
  • 27
  • 42

1 Answers1

6

You need to set a NumberFormat for the rangeAxis like this:

NumberAxis rangeAxis = new NumberAxis("Count");
...
rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
...
XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
...

Or you can do this if you already have a plot

NumberAxis rangeAxis2 = (NumberAxis) plot.getRangeAxis();
rangeAxis2.setNumberFormatOverride(NumberFormat.getPercentInstance());

You should then have an chart that looks like this:

enter image description here

GrahamA
  • 5,875
  • 29
  • 39
  • 3
    +1 for illustration, but see also how to [capture only the active window](http://meta.stackexchange.com/q/99734/163188). – trashgod Jun 26 '12 at 16:01