Datasource X Y line chart

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

Datasource X Y line chart

Post by Randy Kemp » Fri Oct 26, 2001 4:01 pm

How do I construct the datasource for a line chart using this simple X Y example?
X = 1, 2, 3, 4, 5
Y = 1, 2, 3, 4, 5 ?

David Gilbert

RE: Datasource X Y line chart

Post by David Gilbert » Mon Oct 29, 2001 10:38 am

Hi Randy,

You should try, wherever possible, to implement the XYDatasource interface in whatever class you are using to store your data. That way you don't have to copy your data from one structure to another.

Alternatively, you could use the DefaultXYDataSource class which is *supposed* to make it easy to create a chart with some simple data in an array. Unfortunately the current implementation doesn't really make it that easy, because of the multi-dimensional array needed by the constructor not being very intuitive (DefaultXYDataSource will be rewritten for the next release). Here's what you need:

Double[][][] data_array = new Double[][][] { { { new Double(1.0), new Double(5.6) },
{ new Double(2.0), new Double(3.5) },
{ new Double(3.0), new Double(2.4) },
{ new Double(4.0), new Double(4.3) },
{ new Double(5.0), new Double(1.3) } } };

DefaultXYDataSource data = new DefaultXYDataSource(data_array);

Regards,

DG.

Locked