Maybe trivial: XY-Plot with TimeSeries

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

Maybe trivial: XY-Plot with TimeSeries

Post by Harald Faber » Fri Dec 20, 2002 1:26 pm

Hi all,
maybe I miss something trivial, but I don't get the point how to provide data for an XY-Chart. That means on the X-axis I have hours and the y-axis is for the values.
Currently I create a TimeSeriesCollection, containing two BasicTimeSeries (for 2 lines in the graph)

TimeSeriesCollection collection = new TimeSeriesCollection();
this.btsFahrzeuge = createTimeSeriesFahrzeuge(vAlleEinlaufsObjekte);
this.btsTakte = createTimeSeriesTakte(vAlleEinlaufsObjekte);
collection.addSeries( this.btsTakte );
collection.addSeries( this.btsFahrzeuge );

where the BasicTimeSeries are created with

BasicTimeSeries bts = new BasicTimeSeries("Anzahl Fahrzeuge", Hour.class);
bts.add(new Hour(...), new Double(...));

Now I don't know how to implement the getXValue(series, item) and getYValue(series, item) which return Number object while I have Hour for x-axis and Number only for y-axis. Or am I a bit confused? What is item exactly in my case?
Background is that I want to re-paint the XY-Chart with actualized data so that the xy-dataset interface methods are required, right?

Thanks in advance for your help.

Harald Faber

It is trivial (but not well documented in sources ;-))

Post by Harald Faber » Fri Dec 20, 2002 4:07 pm

It is trivial, I have found myself an example in the TimeSeriesCollection and works now with:

public Number getXValue(int series, int item){
BasicTimeSeries ts = null;
TimeSeriesDataPair dp;
TimePeriod period;
long result = 0L;

switch ( series )
{
case 0: ts = this.btsFahrzeuge; break;
case 1: ts = this.btsTakte; break;
}

dp = ts.getDataPair(item);
period = dp.getPeriod();
result = period.getStart();
return new Long(result);
}


I haven't supposed that the handling with TimePeriod and x-axis works via Long values...
OK, I thank myself for the answer. ;-)

Locked