How to create XYDataset

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

How to create XYDataset

Post by Carrie » Tue Feb 11, 2003 10:30 am

I want to plot a graph which show the data against date.
All the data (Date and Data) are stored in array.
How can I create XYDataset by using the array?

I have try to create the XYDataset by the following code, however no data can be plot in the graph

public static XYDataset createMyXYDataset(Double[][] data1, int[][] yr, int[][] month, int[][] day) {

int temp = data1.length;
Object [][][] data = new Object [temp][temp][temp];
for (int i=0; i<temp; i++)
{
data [1][0] = createDateTime(yr[0], month[0]-1, day[0], 0, 0);
data [0][0] = data1;
}

return new DefaultXYDataset(data);
}

Anyone can help me, it's urgent. Many Many Thanks :)

David Gilbert

Re: How to create XYDataset

Post by David Gilbert » Tue Feb 11, 2003 10:40 am

Hi Carrie,

I'd recommend that you use the TimeSeries and TimeSeriesCollection classes. The latter implements the XYDataset interface, and the two classes together provide a reasonably intuitive API to work with.

Regards,

Dave Gilbert

P.S. Before 0.9.5, the TimeSeries class was called BasicTimeSeries.

Carrie

Re: How to create XYDataset

Post by Carrie » Tue Feb 11, 2003 10:51 am

I have try to use BasicTimeSeries before, but I got some problem.
In createTimeSeriesChart, the data format it needs is "XYDataset"
createTimeSeriesChart(String, String, String, XYDataset, boolean)
How can I conver the basicTimeSeries to XYDataset??

David Gilbert

Re: How to create XYDataset

Post by David Gilbert » Tue Feb 11, 2003 10:55 am

Just add the time series to a TimeSeriesCollection. Say you have a series called mySeries:

TimeSeriesCollection dataset = new TimeSeriesCollection(mySeries);

Now you can pass 'dataset' to the chart, because TimeSeriesCollection implements the XYDataset class.

Note that here you have just one series in the collection, but you can add more using the addSeries(...) method.

Regards,

Dave Gilbert

Carrie

Re: How to create XYDataset

Post by Carrie » Tue Feb 11, 2003 11:06 am

Thanks Dave :)

Carrie

Re: How to create XYDataset

Post by Carrie » Tue Feb 11, 2003 11:25 am

In BasicTimeSeries,
SerialDate.JANUARY - what will be return? is it integer??

public static BasicTimeSeries createUSDTimeSeries() {

BasicTimeSeries t1 = new BasicTimeSeries("USD/GBP");
try {
t1.add(new Day(2, SerialDate.JANUARY, 2001), new Double(1.4956));
t1.add(new Day(3, SerialDate.JANUARY, 2001), new Double(1.5047));

Locked