ArrayOutOfBoundsException

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

ArrayOutOfBoundsException

Post by Craig MacFarlane » Mon Nov 06, 2000 5:27 pm

I'm seeing the following exception.

Nov 4, 2000 12:38:09 AM GMT 4 debug
java.lang.ArrayIndexOutOfBoundsException: 51
at
com.jrefinery.chart.VerticalNumberAxis.calculateAutoTickValue(Unknown
Source)
at com.jrefinery.chart.VerticalNumberAxis.refreshTicks(Unknown Source)
at com.jrefinery.chart.VerticalNumberAxis.reserveAxisArea(Unknown
Source)
at com.jrefinery.chart.XYPlot.draw(Unknown Source)
at com.jrefinery.chart.JFreeChart.draw(Unknown Source)

I put debugging statements in my DataSource to
ensure that I implemented the interface correctly
and everything seems to be okay there. Otherwise,
I just did this...

JFreeChart chart =
JFreeChart.createTimeSeriesChart(dataSource);

BufferedImage buffImage = new BufferedImage(600, 300,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = buffImage.createGraphics();
Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 600,
300);
chart.draw(graphics2D, chartArea);

I wouldn't expect VerticalNumberAxis.calculateAutoTickValue to
ever throw an ArrayIndexOutOfBoundsException, but did I
forget some initialization step?

Looking through the code, I found a 51 element
array that it seems to be indexing beyond.

/**
* An array of standard tick sizes used when automatically determining the tick value. These
* values can be changed to whatever you require, as long as: (1) the values remain in
* ascending order; and (2) you update the corresponding array of standard tick formats (see
* below).
*/
protected static Number[] autoTickValues = {
new Double(0.0000001), new Double(0.00000025), new Double(0.0000005),
new Double(0.000001), new Double(0.0000025), new Double(0.000005),
new Double(0.00001), new Double(0.000025), new Double(0.00005),
new Double(0.0001), new Double(0.00025), new Double(0.0005),
new Double(0.001), new Double(0.0025), new Double(0.005),
new Double(0.01), new Double(0.025), new Double(0.05),
new Double(0.1), new Double(0.25), new Double(0.5),
new Long(1), new Double(2.5), new Long(5),
new Long(10), new Long(25), new Long(50),
new Long(100), new Long(250), new Long(500),
new Long(1000), new Long(2500), new Long(5000),
new Long(10000), new Long(25000), new Long(50000),
new Long(100000), new Long(250000), new Long(500000),
new Long(1000000), new Long(2500000), new Long(5000000),
new Long(10000000), new Long(25000000), new Long(50000000),
new Long(100000000), new Long(250000000), new Long(500000000),
new Long(1000000000), new Long(2500000000L), new Long(5000000000L)
};

Anybody have any experience with this one?

Craig

Craig MacFarlane

RE: ArrayOutOfBoundsException

Post by Craig MacFarlane » Mon Nov 06, 2000 8:35 pm

Reversing the x,y values in the data source
will cause this exception to fire.

David Gilbert

RE: ArrayOutOfBoundsException

Post by David Gilbert » Mon Nov 06, 2000 9:49 pm

The code is trying to select a tick unit so that the tick labels won't overlap. I've forgotten to check for the case where even the largest tick unit still has overlapping labels (your data range must be very large...perhaps when you transposed your x and y values the x values were Date objects?) - I'll post a fix soon.

Regards,

DG.

Matt

RE: ArrayOutOfBoundsException

Post by Matt » Wed Nov 08, 2000 5:11 pm

I had this problem too, but it was just as David said, I had transposed Date values as y values. If the chart data causes this exception to be thrown, I doubt it would display anything useful anyway, but a fix would be nice to help the unwary know what's going on...

David Gilbert

RE: ArrayOutOfBoundsException

Post by David Gilbert » Fri Nov 10, 2000 11:10 pm

Matt,

Absolutely. I think the fix should be straightforward...but I'll look at it later!

If there are any other "non-obvious" behaviours in JFreeChart, please e-mail me...only my dog is available for testing the code, and he's not very good.

Regards,

DG.

Fabien D.

RE: ArrayOutOfBoundsException

Post by Fabien D. » Fri Dec 01, 2000 7:33 pm

In another pos, I talk about a bug when there is no data in dataSource and I got exactly the same exception.

Locked