setting range on 3D bar charts

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ken O'Neill

setting range on 3D bar charts

Post by Ken O'Neill » Tue Feb 18, 2003 10:40 pm

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?

Arnaud

Re: setting range on 3D bar charts

Post by Arnaud » Wed Feb 19, 2003 11:13 am

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

David Gilbert

Re: setting range on 3D bar charts

Post by David Gilbert » Wed Feb 19, 2003 1:06 pm

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

Ken O'Neill

Re: setting range on 3D bar charts

Post by Ken O'Neill » Wed Feb 19, 2003 5:42 pm

Worked perfectly. Thanks Arnaud, thanks Dave.

Locked