Barchart not starting at zero?
Barchart not starting at zero?
Hi!
I'm using JFreeChart for an application where I need to display the varaiance of values from a "center line". Is this possible to do? What I'm trying to get at is that I want to be able to have a bar chart (or similar), but with a base value of for example 1, and then draw the bars up and down from that to their "real" values.
Regards,
Markus Svensson
I'm using JFreeChart for an application where I need to display the varaiance of values from a "center line". Is this possible to do? What I'm trying to get at is that I want to be able to have a bar chart (or similar), but with a base value of for example 1, and then draw the bars up and down from that to their "real" values.
Regards,
Markus Svensson
Barchart not starting at zero?
Maybe look into the StatisticalBarRenderer... It provides a scale that shows variance. It's documented under the Renderer package.
-cgw
-cgw
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The base value in the BarRenderer class is hardcoded to zero. The best solution to this problem would be to make the base value an attribute that can be controlled by the developer. It is on the to-do list.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 7
- Joined: Mon Jun 18, 2007 8:15 am
- Location: Kathmandu
- Contact:
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
You might be able to backport the BarRenderer class to an earlier version, but I haven't tried. Wherever possible, you should try to upgrade to the latest version though - there have been many bug fixes and feature enhancements.shamesh_joshi wrote:There's now soln in new version.. but what for the older versions????
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 7
- Joined: Mon Jun 18, 2007 8:15 am
- Location: Kathmandu
- Contact:
One thing that can be done is write your own barchart renderer, add base value and add function calculateBarL0L1(double value)shamesh_joshi wrote:
There's now soln in new version.. but what for the older versions????
eg:
Code: Select all
public class MyBarRenderer extends BarRenderer {
double base=0;
public double getBase() {
return base;
}
public void setBase(double base) {
this.base = base;
}
protected double[] calculateBarL0L1(double value) {
double lclip = getLowerClip();
double uclip = getUpperClip();
double bb = this.base;
if (uclip <= 0.0) { // cases 1, 2, 3 and 4
if (value >= uclip) {
return null; // bar is not visible
}
bb = uclip;
if (value <= lclip) {
value = lclip;
}
}
else if (lclip <= 0.0) { // cases 5, 6, 7 and 8
if (value >= uclip) {
value = uclip;
}
else {
if (value <= lclip) {
value = lclip;
}
}
}
else { // cases 9, 10, 11 and 12
if (value <= lclip) {
return null; // bar is not visible
}
bb = lclip;
if (value >= uclip) {
value = uclip;
}
}
return new double[] {bb, value};
}
}
