hi, sorry about the original post, I tabbed and posted accidentally.
I'm having trouble moving from version 7.0 to 7.1 with combined charts.
My original code no longer works, and I can't figure out what is wrong.
I was overlaying lines on a chart, now I overrun an array deep in the JFreeChart code, seems that somehow the number of items or series is wrong. Any help is appreciated, I'm on a tight deadline.
Here is some stripped down code. Is is possible to do this, and is my syntax correct? In particular I'm confused about how SubSeriesDataset is used. I'm trying to superimpose an arbitrary number of lines on top of a reference line. Datasets appear to be correct when printed out, they are created by Double[1][100][2] arrays which contain 100 xy points. I don't include that lengthy code here.
Thanks very much in advance,
matt
//get data
XYDataset[] datasets = createDatasets(chartType, costValues);
int numGraphs = datasets.length;
CombinedDataset data = new CombinedDataset();
//first add the dataset for the reference line
XYDataset refLineDataset = buildRefDataset(chartType); //see below
data.add(new SubSeriesDataset(refLineDataset, 0));
//now add in the datasets for the lines.
for(int i=0;i<numGraphs;i++){
XYDataset dataset = datasets;
data.add(new SubSeriesDataset(dataset, 0));
}
JFreeChart chart = null;
try {
// common horizontal and vertical axes
HorizontalNumberAxis xAxis = null;
VerticalNumberAxis yAxis = null;
yAxis = new VerticalNumberAxis( yAxisLabel,
Axis.DEFAULT_AXIS_LABEL_FONT,
0.01,
100);
xAxis = new HorizontalNumberAxis(xAxisLabel,
Axis.DEFAULT_AXIS_LABEL_FONT,
0.01,
100);
CombinedPlot overlaidPlot = new CombinedPlot(xAxis, yAxis);
//add the reference line, and the sub-plots
for(int i=0;i<numGraphs+1;i++){
CombinedChart cc =
ChartFactory.createCombinableXYChart(xAxis, yAxis, new SubSeriesDataset(data, i));
overlaidPlot.add(cc);
}
//creating a reference dataset, line at 1.0
private XYDataset buildRefDataset(){
Object[][][] finaldata = new Object[][][] {
{{new Double(0), new Double(1.0)},
{new Double(100), new Double(1.0)}}};
return new DefaultXYDataset(finaldata);
}
sorry, urgent bug please respond
Re: sorry, urgent bug please respond
Hi Matt,
I got this fix e-mailed to me, I think it is probably the same bug:
>>>>>>>>>>>>>>>>>>>>>>>>>>>
Hello David,
I think there is something wrong with CombinedDataset in get{Start/End}{X/Y}Value.
If I change 'series' to 'di.series' in the lines listed below,
the 'Combined and overlaid dynamic chart' demo can be run as well.
Without the changes I get an ArrayIndexOutOfBoundsException.
Best regards,
Gyula
==================================================================================
The diff of the parts in question are as follows:
C:\tmp>diff -u CombinedDataset.java CombinedDataset.java.changed
--- CombinedDataset.java Fri Feb 8 16:33:42 2002
+++ CombinedDataset.java.changed Wed Feb 13 21:44:26 2002
@@ -246,7 +246,7 @@
public Number getStartXValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
if (di.data instanceof IntervalXYDataset) {
- return ((IntervalXYDataset)di.data).getStartXValue(series, item);
+ return ((IntervalXYDataset)di.data).getStartXValue(di.series, item);
}
else {
return getXValue(series, item);
@@ -261,7 +261,7 @@
public Number getEndXValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
if (di.data instanceof IntervalXYDataset) {
- return ((IntervalXYDataset)di.data).getEndXValue(series, item);
+ return ((IntervalXYDataset)di.data).getEndXValue(di.series, item);
}
else {
return getXValue(series, item);
@@ -276,7 +276,7 @@
public Number getStartYValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
if (di.data instanceof IntervalXYDataset) {
- return ((IntervalXYDataset)di.data).getStartYValue(series, item);
+ return ((IntervalXYDataset)di.data).getStartYValue(di.series, item);
}
else {
return getYValue(series, item);
@@ -291,7 +291,7 @@
public Number getEndYValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
if (di.data instanceof IntervalXYDataset) {
- return ((IntervalXYDataset)di.data).getEndYValue(series, item);
+ return ((IntervalXYDataset)di.data).getEndYValue(di.series, item);
}
else {
return getYValue(series, item);
I got this fix e-mailed to me, I think it is probably the same bug:
>>>>>>>>>>>>>>>>>>>>>>>>>>>
Hello David,
I think there is something wrong with CombinedDataset in get{Start/End}{X/Y}Value.
If I change 'series' to 'di.series' in the lines listed below,
the 'Combined and overlaid dynamic chart' demo can be run as well.
Without the changes I get an ArrayIndexOutOfBoundsException.
Best regards,
Gyula
==================================================================================
The diff of the parts in question are as follows:
C:\tmp>diff -u CombinedDataset.java CombinedDataset.java.changed
--- CombinedDataset.java Fri Feb 8 16:33:42 2002
+++ CombinedDataset.java.changed Wed Feb 13 21:44:26 2002
@@ -246,7 +246,7 @@
public Number getStartXValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
if (di.data instanceof IntervalXYDataset) {
- return ((IntervalXYDataset)di.data).getStartXValue(series, item);
+ return ((IntervalXYDataset)di.data).getStartXValue(di.series, item);
}
else {
return getXValue(series, item);
@@ -261,7 +261,7 @@
public Number getEndXValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
if (di.data instanceof IntervalXYDataset) {
- return ((IntervalXYDataset)di.data).getEndXValue(series, item);
+ return ((IntervalXYDataset)di.data).getEndXValue(di.series, item);
}
else {
return getXValue(series, item);
@@ -276,7 +276,7 @@
public Number getStartYValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
if (di.data instanceof IntervalXYDataset) {
- return ((IntervalXYDataset)di.data).getStartYValue(series, item);
+ return ((IntervalXYDataset)di.data).getStartYValue(di.series, item);
}
else {
return getYValue(series, item);
@@ -291,7 +291,7 @@
public Number getEndYValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
if (di.data instanceof IntervalXYDataset) {
- return ((IntervalXYDataset)di.data).getEndYValue(series, item);
+ return ((IntervalXYDataset)di.data).getEndYValue(di.series, item);
}
else {
return getYValue(series, item);
Re: sorry, urgent bug please respond
Thanks David. That looked promising but unfortunately the problem still persists... I'm now using JFreeChart0.7.3 and JCommon-0.5.5, which has the code fix you sent incorporated in it. Do you have any code that overlays lines on a single chart?
matt
The stack trace I get is:
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:491)
at java.util.ArrayList.get(ArrayList.java:307)
at com.jrefinery.data.DefaultXYDataset.getYValue(Unknown Source)
at com.jrefinery.data.SubSeriesDataset.getYValue(Unknown Source)
at com.jrefinery.data.SubSeriesDataset.getEndYValue(Unknown Source)
at com.jrefinery.data.CombinedDataset.getEndYValue(Unknown Source)
at com.jrefinery.data.SubSeriesDataset.getEndYValue(Unknown Source)
at com.jrefinery.data.Datasets.getMaximumRangeValue(Unknown Source)
at com.jrefinery.chart.XYPlot.getMaximumVerticalDataValue(Unknown Source)
at com.jrefinery.chart.VerticalNumberAxis.autoAdjustRange(Unknown Source)
at com.jrefinery.chart.VerticalNumberAxis.configure(Unknown Source)
at com.jrefinery.chart.Plot.setChart(Unknown Source)
at com.jrefinery.chart.JFreeChart.<init>(Unknown Source)
at com.jrefinery.chart.combination.CombinedChart.<init>(Unknown Source)
at com.jrefinery.chart.ChartFactory.createCombinableChart(Unknown Source)
matt
The stack trace I get is:
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:491)
at java.util.ArrayList.get(ArrayList.java:307)
at com.jrefinery.data.DefaultXYDataset.getYValue(Unknown Source)
at com.jrefinery.data.SubSeriesDataset.getYValue(Unknown Source)
at com.jrefinery.data.SubSeriesDataset.getEndYValue(Unknown Source)
at com.jrefinery.data.CombinedDataset.getEndYValue(Unknown Source)
at com.jrefinery.data.SubSeriesDataset.getEndYValue(Unknown Source)
at com.jrefinery.data.Datasets.getMaximumRangeValue(Unknown Source)
at com.jrefinery.chart.XYPlot.getMaximumVerticalDataValue(Unknown Source)
at com.jrefinery.chart.VerticalNumberAxis.autoAdjustRange(Unknown Source)
at com.jrefinery.chart.VerticalNumberAxis.configure(Unknown Source)
at com.jrefinery.chart.Plot.setChart(Unknown Source)
at com.jrefinery.chart.JFreeChart.<init>(Unknown Source)
at com.jrefinery.chart.combination.CombinedChart.<init>(Unknown Source)
at com.jrefinery.chart.ChartFactory.createCombinableChart(Unknown Source)