HanSolo / charts

A JavaFX library that contains different kind of charts
Apache License 2.0
672 stars 83 forks source link

LineChart items xySeries couldn't be cleared in a simple way #88

Open permiakover opened 2 years ago

permiakover commented 2 years ago

Hello, if i need to clear dots in chart for a while (in case of dynamic charts building via XYSeriesBuilder with empty items and calling clear()on items causes

Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    at java.base/java.util.Objects.checkIndex(Objects.java:372)
    at java.base/java.util.ArrayList.get(ArrayList.java:459)
    at javafx.base/com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:89)
    at eu.hansolo.fx.charts.XYPane.drawLine(XYPane.java:717)
    at eu.hansolo.fx.charts.XYPane.drawChart(XYPane.java:675)
    at eu.hansolo.fx.charts.XYPane.redraw(XYPane.java:636)
    at eu.hansolo.fx.charts.XYPane.lambda$registerListeners$8(XYPane.java:229)
    at eu.hansolo.fx.charts.series.Series.fireSeriesEvent(Series.java:467)
    at eu.hansolo.fx.charts.series.Series.lambda$new$0(Series.java:134)
    at javafx.base/com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
    at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
    at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
    at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
    at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
    at javafx.base/com.sun.javafx.collections.ObservableListWrapper.clear(ObservableListWrapper.java:157)

is that normal?

permiakover commented 2 years ago

a working workaround is to xySeries1.setItems(XYChartItem())

HanSolo commented 2 years ago

I‘m currently very busy with conference travel but will take a look soon…I hope 😁