I have a barchart that uses Strings for the X-Axis categories, and numeric values for the Y-Axis values. I can filter the barchart to only display bars within a particular range of values. However, when I try to restore the original values I get a error that I'm attempting to enter duplicate values into the barchart. Here's the code that restores the barchart:
XYChart.Series<String, Number> series = new XYChart.Series<String, Number>();
series.setData(origSeries);
ObservableList<Series<String, Number>> metaSeries = FXCollections.observableArrayList();
metaSeries.add(series);
plot.getData().clear();
plot.setData(metaSeries);
In the second to last line, I clear the series used in the chart. If I add a plot.getData().isEmpty() to the code, it comes back true. There should be no reason for this exception.
Exception in thread "AWT-AppKit" java.lang.IllegalArgumentException: Children: duplicate children added: parent = Group@2417af7e[styleClass=plot-content]
at javafx.scene.Parent$1.onProposedChange(Parent.java:307)
at com.sun.javafx.collections.VetoableObservableList.add(VetoableObservableList.java:165)
at com.sun.javafx.collections.ObservableListWrapper.add(ObservableListWrapper.java:144)
at javafx.scene.chart.BarChart.animateDataAdd(BarChart.java:276)
at javafx.scene.chart.BarChart.seriesAdded(BarChart.java:317)
at javafx.scene.chart.XYChart$2.onChanged(XYChart.java:130)
at javafx.scene.chart.XYChart$3.invalidated(XYChart.java:186)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:129)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
at javafx.beans.property.ObjectProperty.setValue(ObjectProperty.java:84)
at javafx.scene.chart.XYChart.setData(XYChart.java:218)
If I remove the call to clear(), the error message goes away; however the sorted values in the metaseries are not added back in sorted order. And the lengths of the bars in the barchart no longer reflect their actual values. They are all added with the same uniform height. If I attempt to sort the categories from the CategoryAxis (XAxis), nothing happens. If I re-sort the values in the original series, nothing happens. And there doesn't seem to be any way of restoring the barchart to its original state.
XYChart.Series<String, Number> series = new XYChart.Series<String, Number>();
series.setData(origSeries);
ObservableList<Series<String, Number>> metaSeries = FXCollections.observableArrayList();
metaSeries.add(series);
plot.getData().clear();
plot.setData(metaSeries);
In the second to last line, I clear the series used in the chart. If I add a plot.getData().isEmpty() to the code, it comes back true. There should be no reason for this exception.
Exception in thread "AWT-AppKit" java.lang.IllegalArgumentException: Children: duplicate children added: parent = Group@2417af7e[styleClass=plot-content]
at javafx.scene.Parent$1.onProposedChange(Parent.java:307)
at com.sun.javafx.collections.VetoableObservableList.add(VetoableObservableList.java:165)
at com.sun.javafx.collections.ObservableListWrapper.add(ObservableListWrapper.java:144)
at javafx.scene.chart.BarChart.animateDataAdd(BarChart.java:276)
at javafx.scene.chart.BarChart.seriesAdded(BarChart.java:317)
at javafx.scene.chart.XYChart$2.onChanged(XYChart.java:130)
at javafx.scene.chart.XYChart$3.invalidated(XYChart.java:186)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:129)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
at javafx.beans.property.ObjectProperty.setValue(ObjectProperty.java:84)
at javafx.scene.chart.XYChart.setData(XYChart.java:218)
If I remove the call to clear(), the error message goes away; however the sorted values in the metaseries are not added back in sorted order. And the lengths of the bars in the barchart no longer reflect their actual values. They are all added with the same uniform height. If I attempt to sort the categories from the CategoryAxis (XAxis), nothing happens. If I re-sort the values in the original series, nothing happens. And there doesn't seem to be any way of restoring the barchart to its original state.
- relates to
-
JDK-8115651 NPE in charts when data is modified
-
- Closed
-