XChart
XChart copied to clipboard
NoSuchElementException after all data removed
After a chart.getSeriesMap().clear();
, NoSuchElementException is thrown when attempting to
draw the component:
java.util.NoSuchElementException
at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:758)
at java.base/java.util.LinkedHashMap$LinkedValueIterator.next(LinkedHashMap.java:783)
at org.knowm.xchart.internal.chartpart.Axis.getAxisTickCalculator(Axis.java:442)
at org.knowm.xchart.internal.chartpart.Axis.getXAxisHeightHint(Axis.java:287)
at org.knowm.xchart.internal.chartpart.Axis.preparePaint(Axis.java:155)
at org.knowm.xchart.internal.chartpart.AxisPair.paint(AxisPair.java:123)
at org.knowm.xchart.CategoryChart.paint(CategoryChart.java:311)
at org.knowm.xchart.XChartPanel.paintComponent(XChartPanel.java:168)
at java.desktop/javax.swing.JComponent.paint(JComponent.java:1119)
Verified for xchart 3.8.3.
I am able to reproduce the issue. Moreover, the same seems to happen when you don't add any series at all (which is a similar situation to adding series and removing them).
Chart ch = new CategoryChart(800, 600, GGPlot2);
ch.paint(new CustomGraphic(), 20, 20);
yields
java.util.NoSuchElementException
at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:766)
at java.base/java.util.LinkedHashMap$LinkedValueIterator.next(LinkedHashMap.java:791)
at org.knowm.xchart.internal.chartpart.Axis.getAxisTickCalculatorForX(Axis.java:515
I am wondering what is the cleanest behavior here. Likely some sanitization of input and explicit exception with "no series" or something.
Not sure if there should be an exception; I'd prefer just displaying an empty chart.