A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
Augusto
- Posts: 12
- Joined: Wed Jan 21, 2004 9:02 pm
Post
by Augusto » Tue Mar 02, 2004 8:04 pm
I'm trying to set a baseline on Bar and Line charts in the following way.
Say our baseline is 100. For values 150 and 50, 150 will be shown as a bar going up from 100 to 150, and value 50 would be a bar going down from 100 to 50.
Like this;
Code: Select all
175| _
150| |X|
125| |X|
100|...|X|...........
075| |X|
050| |X|
025|
000\--------------->
Bar Chart
How can this be done?
Same for line charts, I'd like a line chart with the fill area based on the baseline value, like this;
Code: Select all
175|
150| /\
125| /++\
100|.../++++\............
075|++/ \++++++++
050|+/ \++/\+++
025|/ \/ \++
000\------------------->
Line Chart
Any help appreciated, I've looked over and over the API but I can't seem to make sense out of this.
-
Augusto
- Posts: 12
- Joined: Wed Jan 21, 2004 9:02 pm
Post
by Augusto » Tue Mar 02, 2004 11:46 pm
Looks like I could sort of do this using an interval dataset for the bar charts, going to try that next. Not sure if it's the right solution though, the data is not an interval, I just want to control how it's rendered by using a non-zero value as the base.
Haven't found anything for the XY Plot though ...
-
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 » Wed Mar 03, 2004 9:57 am
This isn't supported yet. Both the BarRenderer and AreaRenderer classes assume zero as the base. The solution will be to make this an attribute of the renderer, and update the drawing code accordingly...at least I think so, until I try it out I won't know for sure...
-
Augusto
- Posts: 12
- Joined: Wed Jan 21, 2004 9:02 pm
Post
by Augusto » Wed Mar 03, 2004 8:52 pm
David, thanks for the quick reply.
I'll take a look at the area renderer to see what can be done, in the meantime, at least for bars I found a workaround. I can just use this dataset and change the plot renderer to an intertval one. Here's the class;
Code: Select all
/**
* Category set that implements a non zero base line value, so that
* bars can be rendered with a specified baseline value that is not
* zero.
*/
class BaselineCategoryDataset extends DefaultCategoryDataset implements
IntervalCategoryDataset
{
Number baseline = new Double(0.0);
public BaselineCategoryDataset()
{
this(0.0);
}
public BaselineCategoryDataset(double baseline)
{
setBaseline(baseline);
}
public void setBaseline(double baseline)
{
this.baseline = new Double(baseline);
}
public Number getEndValue(Comparable series, Comparable category)
{
return getStartEndValue(super.getValue(series, category), false);
}
public Number getEndValue(int series, int category)
{
return getStartEndValue(super.getValue(series, category), false);
}
public Number getStartValue(Comparable series, Comparable category)
{
return getStartEndValue(super.getValue(series, category), true);
}
public Number getStartValue(int series, int category)
{
return getStartEndValue(super.getValue(series, category), true);
}
private Number getStartEndValue(Number value, boolean start)
{
Number retval = null;
if (value != null)
{
boolean lessThan = (value.doubleValue() < baseline.doubleValue());
if (start)
{
retval = (lessThan) ? value : baseline;
}
else
{
retval = (!lessThan) ? value : baseline;
}
}
return retval;
}
}
-
Augusto
- Posts: 12
- Joined: Wed Jan 21, 2004 9:02 pm
Post
by Augusto » Wed Sep 28, 2005 9:15 pm
OK, i'm back with the same question. Is this something that is supported now?
I'm interested in doing this baseline with an area/line chart as described in the original post, any ideas?
Thanks
-
Augusto
- Posts: 12
- Joined: Wed Jan 21, 2004 9:02 pm
Post
by Augusto » Thu Sep 29, 2005 6:20 am
Well I made two minor line changes to XYAreaRenderer to use a variable instead of zero for the fill area and it works. I was hoping I could do this with subclassing, but it seems impossible.
Could anybody clarify the license a bit? Am I allowed to make a copy of that file, modify it and distribute if I just post the code back? I'm not 100% sure ...
thanks
-
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 » Thu Sep 29, 2005 3:59 pm
If you modify JFreeChart, you can redistribute the modified version under the terms of the LGPL. You need to make the JFreeChart source code (including your modifications) available to everyone (and only those) that you distribute it to.
Regarding the baseline feature, some of the renderers support this already, and there are some that don't but should.