2 Replies Latest reply on Dec 12, 2012 11:59 PM by mfortner

    Can't clear barchart

      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>();
              ObservableList<Series<String, Number>> metaSeries = FXCollections.observableArrayList();
      Here's the question: 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. So why, does the last line give me this error:
      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)
        • 1. Re: Can't clear barchart
          Looks similar to this bug: http://javafx-jira.kenai.com/browse/RT-25187 "Charts - duplicate children added when sorting the chart data".

          But the use case is slightly different, so it is probably worth filing a new bug report linking to RT-25187 in the description or comments and including a simple, executable test case which reproduces the issue. File the bug under runtime at http://javafx-jira.kenai.com.

          You might want to try running the code on jdk8 early access build (http://jdk8.java.net/download.html) first to see if the bug has already been fixed for the next version of JavaFX.
          • 2. Re: Can't clear barchart
            Done. http://javafx-jira.kenai.com/browse/RT-26955

            I also discovered that if I don't clear the series, it allows me to replace the series, but the Y-Axis values don't display correctly, and the values are not sorted properly (even if they're added in sorted order. The values seem to be appended onto the end of the CategoryAxis.