【问题标题】:removing existing timeseries from dataset in Jfreechart从 Jfreechart 中的数据集中删除现有时间序列
【发布时间】:2014-03-17 15:37:35
【问题描述】:

我正在使用 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”而改变。时间序列被动态添加。如果时间序列已经存在,我不想添加它。如何检查时间序列是否已经存在以及是否存在我要删除它。?

【问题讨论】:

    标签: eclipse time-series jfreechart e4


    【解决方案1】:

    每个TimeSeries 都有一个密钥来识别它。要查看 TimeSeriesCollection 中是否存在 TimeSeries,请使用该类中的 getSeries(Comparable) 方法 - 如果没有具有该键的序列,它将返回 null。如果返回非空值,则可以调用removeSeries(TimeSeries)方法将其移除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-06
      • 2023-03-22
      • 1970-01-01
      • 2018-05-08
      • 1970-01-01
      • 2014-09-08
      • 2015-11-24
      • 1970-01-01
      相关资源
      最近更新 更多