Page 1 of 1

Show stopper in Box Plot

Posted: Wed Jun 25, 2008 7:16 pm
by 7667592
Hello,

I have come across a critical bug in Box Plot.

It does not behave well if I happen to give it only two values to plot in a series.

Am I doing something wrong? I understand that two values is not a normal number of values for a Box, but I feel like TeeChart should not throw an exception. Rather it should degrade gracefully.

One of my co-workers found that setUseCustomValues seems to fix things. I don't think this is applicable though. I am not needing to override the standard algorithm for calculating the structure of the box.

Here is the failing code:

Code: Select all

public static void main(String[] args){
		JFrame frame = new JFrame("Unhappy Box");
		TChart teeChart = new TChart();
		teeChart.setBackColor(new Color(255, 255, 255));
		teeChart.getAspect().setView3D(false);

		Box box1 = new Box(teeChart.getChart());
		double[] yvals = new double[] { 10.0,30.0 };
		box1.setPosition(1.0);
		box1.add(yvals);
		
		frame.getContentPane().add(teeChart);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);

	}
Here is the Exception:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at com.steema.teechart.styles.CustomBox.percentile(CustomBox.java:194)
at com.steema.teechart.styles.CustomBox.reconstructFromData(CustomBox.java:217)
at com.steema.teechart.styles.CustomBox.doBeforeDrawValues(CustomBox.java:262)
at com.steema.teechart.styles.Series.drawSeries(Series.java:2215)
at com.steema.teechart.Chart.internalDraw(Chart.java:670)
at com.steema.teechart.Chart.paint(Chart.java:1807)
at com.steema.teechart.TChart.paintComponent(TChart.java:568)
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.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Posted: Thu Jun 26, 2008 11:57 am
by narcis
Hi Jesse,

Considering TeeChart's implementation of BoxPlot series we don't think it makes much sense drawing a 2-point boxplot.

Anyway, you can still use manual calculation to construct box plot if you use different percentile definition. At the forums threads below you'll find information on how to use different percentile modes:

http://www.teechart.net/support/viewtopic.php?t=5645
http://www.teechart.net/support/viewtopic.php?t=2599

Hope this helps!

Posted: Thu Jun 26, 2008 3:20 pm
by 7667592
So the answer to my question is "Yes, you are doing something wrong. Don't send in exactly 2 data values. 1, 3, or more is ok."

I was not implying that you would plot the data. I'm suggesting that it should not crash based upon user data and that it is not the responsibility of a user of a library to do error checking for said library. At the very least, throwing ArrayIndexOutOfBounds is not an appropriate exception for such an edge case.

Posted: Mon Jun 30, 2008 1:33 pm
by narcis
Hi Jesse,

Thanks for your feedback. We are currently working on fixing the issue for next update version. We will get back to you when we have further news.

Posted: Tue Jul 01, 2008 2:58 pm
by narcis
Hi Jesse,

We have just implemented new boxplot percentile calculation which supports box plots formed with 2 values only for next maintenance release.