sugestions to time charts

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ricardo Trindade

sugestions to time charts

Post by Ricardo Trindade » Tue Dec 17, 2002 4:38 pm

Hi,

I'd like to know if the following is implemented, and if not, to sugest it :

-being able to identify by name the series added to a chart (if it's possible to do it now I really didn't find it in the javadoc), so that it's easy to write points to those series later.

-being able to limit the number of points in a chart, in such a way that when new points are added beyond this limit, old points are automatically dropped. This is usefull for real time representation of values, in TimeSeries.

I also noticed a bug in addOrUpdate, using TimeSeries. With this method the chart isn't updated. I already reported this once, so it's probably fixed in the CVS, but just in case.

bye
Ricardo Trindade

Jamey Johnston

Re: sugestions to time charts

Post by Jamey Johnston » Tue Dec 17, 2002 6:06 pm

I use a TreeMap (could use a HashMap if you do not care if it is stored sorted) to store a "Name" for the series as the Key and the BasicTimeSeries (in my application) as the value. Below is a sample of the code I used. I setup my Map and TimeSeriesCollection (dataset). I instaniate a new BasicTimeSeries, set the HstoryCount, and add the BasicTimeSeries to the dataset. Whenever I want to add a point to a BasicTimeSeries Iterate through my TreeMap to find the "Name" (key) of the series I am looking for then I cast my value (BasicTimeSeries) and add the point. (See Code Below)

If you look at the code "bts.setHistoryCount(....)" this will limit the amount of data that a BasicTimeSeries will hold data. Not sure what type of Series you are plotting.

Not sure if this is the most effecient way to do this. But I did not see a way in the BasicTimeSeries class or TimeSeriesCollection to do this.

Regards,

Jamey Johnston


------------------------------------------
private Map seriesMap = Collections.synchronizedMap(new TreeMap());
private TimeSeriesCollection dataset;
dataset = new TimeSeriesCollection();

....

BasicTimeSeries bts = new BasicTimeSeries("Name", Millisecond.class);
bts.setHistoryCount(900000);
seriesMap.put("Name", bts);
dataset.addSeries(bts);

...

Iterator seriesMapIT = seriesMap.entrySet().iterator();
Millisecond now = new Millisecond();

while (seriesMapIT.hasNext())
{
Map.Entry eSeries = (Map.Entry)seriesMapIT.next();
if (eSeries.getKey().equals("Name")
{
((BasicTimeSeries)eSeries.getValue()).add(now, 0.0);
}
}

Locked