Hi,
I m new to JFreeChart
I m trying to draw Combine chart which uses same range Axis and same
DomainAxis,but i m not getting that.
i got some examples which uses
CombinedDomainCategoryPlot and CombinedRangeCategoryPlot Classes
to draw a combine chart but it is either having same range Axis or same DomainAxis.
but i want the chart that uses same range Axis and DomainAxis.
is thr any classes or method in Jfreechart to do this?
If anyBody know please help me.
thanks and regards
mann
Combine Chart in jfreechart
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
I did this in an earlier post in response to my own request (see request: CombinedDomainAndRange*Plot). The class(es) presented in that thread do(es) share a common domain and range axes between all the subplots. The range axis though has a problem where it does not autorange correctly to reflect the data in all the subplots. Due to how the ValueAxis computes its range, the autorange was only based upon the data in the last subplot. I have since found a solution which I present below, and I will be packaging it up as a patch in the trackers.
The commented line "//l_subplot.setRangeAxis(l_axis, false);" represents an optimization that would prevent the plot from being redrawn during each iteration of the loop. While "l_subplot.setRangeAxis(0, l_axis, false);" achieves the same result, I feel the commented line is a more natural function call as I describe in Patch 1913751.
Code: Select all
import java.util.Iterator;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.Range;
public class CombinedXYPlot
extends CombinedDomainXYPlot
{
public CombinedXYPlot (ValueAxis x_domain, ValueAxis x_range)
{
super(x_domain);
super.setGap(10.0);
super.setRangeAxis(x_range);
}
public void add (XYPlot x_subplot)
{
this.add(x_subplot, 1);
}
public void add (XYPlot x_subplot, int x_weight)
{
super.add(x_subplot, x_weight);
updateRangeAxis();
}
public void setRangeAxis (ValueAxis x_range)
{
super.setRangeAxis(x_range);
updateRangeAxis();
}
protected void updateRangeAxis ()
{
ValueAxis l_axis = super.getRangeAxis();
Range l_range = l_axis.getRange();
Iterator l_itr = getSubplots().iterator();
while (l_itr.hasNext()) {
XYPlot l_subplot = (XYPlot)l_itr.next();
l_subplot.setRangeAxis(l_axis);
//l_subplot.setRangeAxis(l_axis, false);
l_range = Range.combine(l_range, l_subplot.getDataRange(l_axis));
}
l_axis.setRange(l_range);
l_axis.resizeRange(0.0);
}
}
Code: Select all
import java.util.Iterator;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.CombinedDomainCategoryPlot;
import org.jfree.data.Range;
public class CombinedCategoryPlot
extends CombinedDomainCategoryPlot
{
public CombinedCategoryPlot (CategoryAxis x_domain, ValueAxis x_range)
{
super(x_domain);
super.setGap(10.0);
super.setRangeAxis(x_range);
}
public void add (CategoryPlot x_subplot)
{
this.add(x_subplot, 1);
}
public void add (CategoryPlot x_subplot, int x_weight)
{
super.add(x_subplot, x_weight);
updateRangeAxis();
}
public void setRangeAxis (ValueAxis x_range)
{
super.setRangeAxis(x_range);
updateRangeAxis();
}
protected void updateRangeAxis ()
{
ValueAxis l_axis = super.getRangeAxis();
Range l_range = l_axis.getRange();
Iterator l_itr = getSubplots().iterator();
while (l_itr.hasNext()) {
CategoryPlot l_subplot = (CategoryPlot)l_itr.next();
l_subplot.setRangeAxis(l_axis);
//l_subplot.setRangeAxis(l_axis, false);
l_range = Range.combine(l_range, l_subplot.getDataRange(l_axis));
}
l_axis.setRange(l_range);
l_axis.resizeRange(0.0);
}
}
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
This has been submitted as Patch 1924543.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
In further discussion with David, we have agreed to not add the commented form of setRangeAxis (and setDomainAxis). UseRichardWest wrote:The commented line "//l_subplot.setRangeAxis(l_axis, false);" represents an optimization that would prevent the plot from being redrawn during each iteration of the loop. While "l_subplot.setRangeAxis(0, l_axis, false);" achieves the same result, I feel the commented line is a more natural function call as I describe in Patch 1913751.
Code: Select all
l_subplot.setRangeAxis(0, l_axis, false);
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA