I'm plotting a 3D bar chart where the data may range from 0 to 1. In order to compare chart to chart I always want the vertical axis scale to run from 0 to 1, regardless of whether any of the data bars gets that high. To override the autoscaling I coded:
JFreeChart chart = ChartFactory.createVerticalBarChart3D(
null, // title to be filled in later
"Category", // x axis label
"Percent", // y axis label
dataset, // data
true // include legend
);
Plot plot = chart.getPlot();
Range yRange = new Range(0.0, 1.0);
VerticalNumberAxis vaxis = new VerticalNumberAxis("Percent");
vaxis.setRange(yRange);
((CategoryPlot) plot).setRangeAxis(vaxis);
This sets the range scale, but the vertical bars are no longer rendered in 3D as I intended.
Any suggestions?
setting range on 3D bar charts
Re: setting range on 3D bar charts
Hello,
If You have a look on the code of the ChartFactory.createVerticalBarChart3D method, You'll read the following (version 0.9.6) :
" [...]
CategoryAxis categoryAxis = new HorizontalCategoryAxis(categoryAxisLabel);
ValueAxis valueAxis = new VerticalNumberAxis3D(valueAxisLabel);
[...] "
So :
- [1] there is a special axis for the 3D.
- [2] You should get the existing axis of Your chart/plot and not try not create a new one.
--> solution : try smthing like (not tested) :
Range yRange = new Range(0.0, 1.0);
VerticalNumberAxis3D vaxis = (VerticalNumberAxis3D) (((VerticalCategoryPlot) plot).getRangeAxis());
vaxis.setRange(yRange)
Regards,
Arnaud
If You have a look on the code of the ChartFactory.createVerticalBarChart3D method, You'll read the following (version 0.9.6) :
" [...]
CategoryAxis categoryAxis = new HorizontalCategoryAxis(categoryAxisLabel);
ValueAxis valueAxis = new VerticalNumberAxis3D(valueAxisLabel);
[...] "
So :
- [1] there is a special axis for the 3D.
- [2] You should get the existing axis of Your chart/plot and not try not create a new one.
--> solution : try smthing like (not tested) :
Range yRange = new Range(0.0, 1.0);
VerticalNumberAxis3D vaxis = (VerticalNumberAxis3D) (((VerticalCategoryPlot) plot).getRangeAxis());
vaxis.setRange(yRange)
Regards,
Arnaud
Re: setting range on 3D bar charts
Arnaud is correct.
The reason you see the 3D effect disappearing is because you are replacing the '3D' axis with a regular VerticalNumberAxis. You don't need to replace the axis at all, just grab a reference to the existing one...
Regards,
Dave Gilbert
The reason you see the 3D effect disappearing is because you are replacing the '3D' axis with a regular VerticalNumberAxis. You don't need to replace the axis at all, just grab a reference to the existing one...
Regards,
Dave Gilbert