Acjb
Acjb

Reputation: 515

removing existing timeseries from dataset in Jfreechart

I am using eclipse e4. I have three timeseries which has inputs dynamically from 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]);
            }

}

After the series are displayed in Jfreechart. In my code the timeseries may change depending on the "statValue" that I select from my GUI. The timeseries gets dynamically added. I do not want to add the timeseries if it is already present. How to check if timeseries is already present and is it is present I want to remove it.?

Upvotes: 0

Views: 281

Answers (1)

David Gilbert
David Gilbert

Reputation: 4477

Every TimeSeries has a key to identify it. To see if a TimeSeries exists in a TimeSeriesCollection use the getSeries(Comparable) method in that class - it will return null if there is no series with that key. If it returns a non-null value, then you can call the removeSeries(TimeSeries) method to remove it.

Upvotes: 2

Related Questions