从Jfreechart的数据集中删除现有的时间序列



我使用的是eclipse e4。我有三个时间序列,它们从GUI动态输入。

/*some code to calculate the entries from a hashmap*/
for (i = 0; i < statValue.length; i++) {
            if(statValue[i].equals("MIN"))
            {
            timeseries[i] = new TimeSeries(entries.getKey()+statValue[i],Second.class);
            }
            if(statValue[i].equals("MAX"))
            {
            timeseries[i] = new TimeSeries(entries.getKey()+statValue[i],Second.class);
            }
            if(statValue[i].equals("AVG"))
            {
            timeseries[i] = new TimeSeries(entries.getKey()+statValue[i],Second.class);
            }       
/* some code to calcluate the input to the timeseries */
if(statValue[i].equals("MIN")){
            for(Entry<Timestamp,Long> seriesData : MinutesToMin.entrySet()){
                System.out.println(new Second(seriesData.getKey())+" "+seriesData.getValue());
                timeseries[i].add(new Second(seriesData.getKey()), seriesData.getValue());
            }
            dataset.addSeries(timeseries[i]);
            }
            System.out.println("MAX");
            if(statValue[i].equals("MAX")){
            for(Entry<Timestamp,Long> seriesData : MinutesToMax.entrySet()){
                System.out.println(new Second(seriesData.getKey())+" "+seriesData.getValue());
                timeseries[i].add(new Second(seriesData.getKey()), seriesData.getValue());
            }
            dataset.addSeries(timeseries[i]);
            }
            System.out.println("AVG");
            if(statValue[i].equals("AVG")){
            for(Entry<Timestamp,Long> seriesData : MinutesToAvg.entrySet()){
                System.out.println(new Second(seriesData.getKey())+" "+seriesData.getValue());
                timeseries[i].add(new Second(seriesData.getKey()), seriesData.getValue());
            }
            dataset.addSeries(timeseries[i]);
            }

}

在Jfreechart中显示序列后。在我的代码中,时间序列可能会根据我从GUI中选择的"statValue"而改变。时间序列是动态添加的。如果时间序列已经存在,我不想添加它。如何检查时间序列是否已经存在,以及它是否存在,我想删除它。

每个TimeSeries都有一个键来标识它。要查看TimeSeries是否存在于TimeSeriesCollection中,请使用该类中的getSeries(Comparable)方法—如果没有具有该键的系列,它将返回null。如果它返回一个非空值,那么您可以调用removeSeries(TimeSeries)方法来删除它。

最新更新