Barchart not starting at zero?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Guest

Barchart not starting at zero?

Post by Guest » Mon Jun 21, 2004 12:51 pm

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

Guest

Post by Guest » Thu Jul 01, 2004 11:04 pm

am facing the same problem. could anyone let me know the solution to the same.

regards,
Sumit.

weckenmc
Posts: 3
Joined: Mon Jun 21, 2004 3:07 pm
Location: Florida

Barchart not starting at zero?

Post by weckenmc » Mon Aug 02, 2004 8:05 pm

Maybe look into the StatisticalBarRenderer... It provides a scale that shows variance. It's documented under the Renderer package.

-cgw

mskjeret
Posts: 27
Joined: Sun May 23, 2004 8:58 am

Post by mskjeret » Sat Aug 07, 2004 11:45 am

Hi

Did anyone find a solution for this?
I tried to set the center value on the plot, but I am not sure that is the method that should be used.
Did not give a visible result either.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Aug 10, 2004 10:07 am

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

shamesh_joshi
Posts: 7
Joined: Mon Jun 18, 2007 8:15 am
Location: Kathmandu
Contact:

Post by shamesh_joshi » Mon Jun 18, 2007 8:29 am

There's now soln in new version.. but what for the older versions????

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Jun 18, 2007 9:56 am

shamesh_joshi wrote:There's now soln in new version.. but what for the older versions????
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.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

shamesh_joshi
Posts: 7
Joined: Mon Jun 18, 2007 8:15 am
Location: Kathmandu
Contact:

Post by shamesh_joshi » Tue Mar 18, 2008 2:08 pm

shamesh_joshi wrote:
There's now soln in new version.. but what for the older versions????
One thing that can be done is write your own barchart renderer, add base value and add function calculateBarL0L1(double value)

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};
        }
}
I took this code from newer version :) of JFreeChart

Locked