Problem

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

Problem

Post by Balu Masti » Fri Jul 21, 2000 12:07 am

Hi,

I was trying to plot an XY graph using JFreeChart - it turned out that
the Y values were all zeroes (about 10000 values). The JFreeChart
based application crashed dumping the following exception:

Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException
at com.jrefinery.chart.VerticalNumberAxis.calculateAutoTickUnits(Vertica
lNumberAxis.java, Compiled Code)
at com.jrefinery.chart.VerticalNumberAxis.refreshTicks(VerticalNumberAxi
s.java, Compiled Code)
at com.jrefinery.chart.VerticalNumberAxis.reserveAxisArea(VerticalNumber
Axis.java:260)
at com.jrefinery.chart.XYPlot.draw(XYPlot.java, Compiled Code)
at com.jrefinery.chart.JFreeChart.draw(JFreeChart.java:294)
at com.jrefinery.chart.JFreeChartPanel.paintComponent(JFreeChartPanel.ja
va:60)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Could you suggest a quick fix for this? I am trying to go through the
source code, but thought of saving time if you could offer any suggestion.

Thanks,
-Balu Masti

David Gilbert

RE: Problem

Post by David Gilbert » Fri Jul 21, 2000 10:21 am

Hi Balu,

Thanks for reporting this bug!

The code is not selecting an "auto" tick unit correctly when the axis range is zero (which results from all your data values being zero). I was able to reproduce the problem with a small data set where the y-values are all the same (zero, or ten, or whatever). I'm going to re-organise this code a little for the next release of JFreeChart, and hopefully find a good solution to the problem.

In the meantime, the following quick fix should make the exception go away (please let me know if it doesn't work for you):

In VerticalNumberAxis.calculateAutoTickUnits(), add the lines marked ** to the code:

** if (fitsIndex>0) {
fitsNotIndex = fitsIndex-1;
while (tickLabelsFit( this.translatedValue( autoTickValues[ fitsNotIndex ], plotArea)-zero, g2)) {
fitsIndex = fitsNotIndex;
fitsNotIndex = fitsNotIndex-1;
** if (fitsIndex==0) break;
}
** }

Thanks again for reporting the bug.

Regards,

DG.

Locked