Javafx图表中的错误:添加了重复的系列。为什么?

时间:2018-10-03 10:05:53

标签: java javafx charts

我正在尝试刷新JavaFX中的图表,但出现错误:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Duplicate series added

这是我的代码:

private XYChart.Series<Number, Number> frequenciesSource;
private double timeStamp=System.currentTimeMillis();
private LineChart<Number, Number> lineChart;

(...)

   Platform.runLater(()
    -> {
        lineChart.getData().remove(frequenciesSource);
        if (0!=frequenciesSource.getData().size()) {
            System.out.println("FrequenceyCharts.update : frequenciesSource.size !=0 => LET'S EMPTY IT !");
            frequenciesSource.getData().remove(0, frequenciesSource.getData().size());
        } else {
            System.out.println("FrequenceyCharts.update : frequenciesSource.size == 0");

        System.out.println("FrequencyCharts.update : linechart contains frequenciesSource ? "+lineChart.getData().contains(frequenciesSource));
        int dotsNumber=0;
        for (float[] chartPoint:chartPoints) {              
            dotsNumber+=1;
            if (dotsNumber<100 && 0!=chartPoint[0]) {   
                frequenciesSource.getData().add(new XYChart.Data<Number, Number>((Number) chartPoint[0],(Number) chartPoint[1]));               
            }
        }
        System.out.println("FrequencyCharts.update : linechart empty ? "+lineChart.getData().isEmpty());
        lineChart.getData().add(frequenciesSource);
    }
);

而且,这是控制台中显示的结果:

FrequenceyCharts.update : frequenciesSource.size == 0
FrequencyCharts.update : linechart contains frequenciesSource ? false
FrequencyCharts.update : linechart empty ? true 
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Duplicate series added

确定为引起问题的行是:

lineChart.getData().add(frequenciesSource);

我的系列frequenciesSource不在我的lineChart中,并且lineChart为空。那么,为什么在尝试添加此错误时会出现“添加了重复系列”错误?

感谢您的帮助。 :-)

0 个答案:

没有答案