Hello,
I just tried to upgrade from JFreeChart 8.1 to 9.1.
I needed to change a couple of things, especially my combined graphs.
Everything works again now, but I still have one problem.
For a combined graph, I always start from a CombinedXYPlot, adding the subplots(XYPlots) and
then I create the chart...
When I have empty datasets for my subplots, I get a NullPointerException.
java.lang.NullPointerException
at com.jrefinery.data.Range.combine(Unknown Source)
at com.jrefinery.chart.CombinedXYPlot.getHorizontalDataRange(Unknown Source)
at com.jrefinery.chart.HorizontalDateAxis.autoAdjustRange(Unknown Source)
at com.jrefinery.chart.HorizontalDateAxis.configure(Unknown Source)
at com.jrefinery.chart.CombinedXYPlot.add(Unknown Source)
I traced the code a bit and found the following:
in every call "CombinedXYPlot.add(...)" Range.combine(..., ...) is called(in getHorizontalDataRange()).
When my dataset is empty, I get Range.combine(null, null) here which gives me this NullPointerException.
public static Range combine(Range range1, Range range2) {
System.out.println("combine: " + "range1: " + range1 + ", range2: " + range2);
Range result = null;
else if ((range1!=null) && (range2==null)) {
result = range1;
}
else if ((range1==null) && (range2!=null)) {
result = range2;
}
else {
double l = Math.min(range1.getLowerBound(), range2.getLowerBound());
double u = Math.max(range1.getUpperBound(), range2.getUpperBound());
result = new Range(l, u);
}
return result;
}
When I add the following code to "combine"
if ((range1==null) && (range2==null)) {
result = new Range(0, 0);
}
I get the desired result.
My question is, is this a bug or am I doing something wrong causing this?
Greetings,
Isabelle
By the way, JFreeChart is great!
NullPointerException, combined charts with empty dataset
Re: NullPointerException, combined charts with empty dataset
Hi Isabelle,
A bug has been fixed in the Range.combine(...) method to handle the case where both ranges are null - it now returns null in this case (or will when 0.9.3 is released).
That will prevent the null pointer exception you are seeing, but I'm not sure whether the return value of null (compared to the Range(0,0) in your fix) will cause you any problems. It depends on your code...are you able to try out the CVS version of JFreeChart?
Regards,
DG.
A bug has been fixed in the Range.combine(...) method to handle the case where both ranges are null - it now returns null in this case (or will when 0.9.3 is released).
That will prevent the null pointer exception you are seeing, but I'm not sure whether the return value of null (compared to the Range(0,0) in your fix) will cause you any problems. It depends on your code...are you able to try out the CVS version of JFreeChart?
Regards,
DG.