Getting Exception: "Requires xLow < xHigh" when zooming in

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Biene_Maja
Posts: 3
Joined: Wed Dec 07, 2011 11:30 pm
antibot: No, of course not.

Getting Exception: "Requires xLow < xHigh" when zooming in

Post by Biene_Maja » Wed Dec 07, 2011 11:44 pm

Hi,

if i zoom endlessly in a diagramm i get an Exception:

Code: Select all

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Requires xLow < xHigh.
	at org.jfree.chart.renderer.RendererUtilities.findLiveItemsLowerBound(RendererUtilities.java:76)
	at org.jfree.chart.renderer.RendererUtilities.findLiveItems(RendererUtilities.java:261)
	at org.jfree.chart.plot.XYPlot.render(XYPlot.java:3819)
	at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:3389)
	at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1237)
	at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1677)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
	at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
	at javax.swing.RepaintManager.paint(Unknown Source)
	at javax.swing.JComponent._paintImmediately(Unknown Source)
	at javax.swing.JComponent.paintImmediately(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)
i even tried some of the examples (Annotation Demo1 for example) and i got the same. It works till there are no more numbers on the axis. If i then zoom in ~20-30 more times i get the exception. In another thread it was suggested to use setAutoRangeMinimumSize(1.0). But that doesn't seem to work.

mkrauskopf
Posts: 31
Joined: Thu May 27, 2010 4:23 pm
antibot: No, of course not.

Re: Getting Exception: "Requires xLow < xHigh" when zooming

Post by mkrauskopf » Thu Dec 08, 2011 4:41 pm

Hi. I guess you should file an issue into the JFreeChart tracker. IMHO a plot (in this case XYPlot) should not allow to zoom in once the interval is actually zero if it not subsequently able to render it. XYPlot#zoom(Domain|Range)Axes sets zero Range but cannot handle it subsequently in the XYPlot#render method.

I guess it can be workarounded within your code.

Biene_Maja
Posts: 3
Joined: Wed Dec 07, 2011 11:30 pm
antibot: No, of course not.

Re: Getting Exception: "Requires xLow < xHigh" when zooming

Post by Biene_Maja » Thu Dec 08, 2011 8:00 pm

Here is a minimal example:

Code: Select all

 public static void main(String[] args) {
	 XYSeries series = new XYSeries("series1");
	 series.add(5, 4);
	 series.add(4, 3);
	 XYSeriesCollection dataset = new XYSeriesCollection();
	 dataset.addSeries(series);
	 JFreeChart chart = ChartFactory.createXYLineChart("Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false);
	 ChartFrame frame = new ChartFrame("chart", chart);
	 frame.pack();
	 frame.setVisible(true);
	 }
just keep zooming in and you will get the Exception after the numbers dissapeared and you keep zooming in. It's not if it hangs the app or anything but the exception is thrown. I don't really know how to work around it, cause it's all "internaly" as seen by the exception stack trace and my code has nothing to do with it.

mkrauskopf
Posts: 31
Joined: Thu May 27, 2010 4:23 pm
antibot: No, of course not.

Re: Getting Exception: "Requires xLow < xHigh" when zooming

Post by mkrauskopf » Fri Dec 09, 2011 8:43 am

cause it's all "internally" as seen by the exception stack trace and my code has nothing to do with it.
Yup, you are right (I think) - that's why you should file issue against the JFreeChart tracker.

There are more ways to prevent (workaround) the exception, the easier one which comes to my mind is ensuring that axis range length is never zero. E.g. add this to your class and call the tweaked (and simplified) createXYLineChart instaed of original method in ChartFactory.

Code: Select all

public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel,
      XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
  NumberAxis xAxis = newTweakedNumberAxis(xAxisLabel);
  xAxis.setAutoRangeIncludesZero(false);
  NumberAxis yAxis = newTweakedNumberAxis(yAxisLabel);
  XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
  XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
  plot.setOrientation(orientation);
  JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
  return chart;
}

private static NumberAxis newTweakedNumberAxis(String label) {
  return new NumberAxis(label) {
    @Override
    public void setRange(Range sRange) {
      super.setRange(sRange.getLength() == 0
              ? new Range(sRange.getLowerBound(), sRange.getLowerBound() + 1e-10)
              : sRange);
    }
  };
}
You will want to probably use more sophisticated math based on actual getLowerBound() value.

Cheers,
-- m.

Biene_Maja
Posts: 3
Joined: Wed Dec 07, 2011 11:30 pm
antibot: No, of course not.

Re: Getting Exception: "Requires xLow < xHigh" when zooming

Post by Biene_Maja » Mon Dec 12, 2011 6:10 pm

Thx for your answers will use what you suggested.

Seems the "bug" is already in the tracker
http://sourceforge.net/tracker/index.ph ... tid=115494

TzlaD
Posts: 1
Joined: Fri Jun 08, 2012 10:00 am
antibot: No, of course not.

Re: Getting Exception: "Requires xLow < xHigh" when zooming

Post by TzlaD » Fri Jun 08, 2012 10:11 am

Hey there,

I have also been bugged with this issue and my observations lead to the opinion that when zooming in the double values due to their precision issues will have values that will be xLow > xHigh.
I tried to zoom on the sides of the plot which should lead to 0.0 on the low end and Infinity on the other (See overflow of double values). If you then try to zoom infinitely nothing happens since the overflow values will always be smaller or equal respectively bigger or equal to the overflow value of double. But if you then try to zoom again, now not starting/ending at the plots (lower/left)/(right/upper) edge you will enconter the same exception... since new values seem to be calculated.

This brings me to the conclusion that the precision of the doulbe value is what causes this unwanted behaviour. Maybe that helps a bit when trying to find a solution!?


I can't see any clean solution so far, but would highly appreciate any more hints.

Cheers TzlaD

Locked