reference to an object

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

reference to an object

Post by Hostos Monegro » Wed Nov 06, 2002 7:59 pm

Hi,

After clicking on one of the bars in my bar (created with VerticalXYBarRenderer class), I output the entity of the click on any given bar and the output is:

com.jrefinery.chart.entity.XYItemEntity@785d65

I think that, that represents a reference to a bar object. Below I have pasted the code for the bars Dataset.

My questions is:

1. How do I retrieve data from that object ( X-axis value, y-axis value, any individual information about the data, etc...)?




____________________________________________________________
/**
* Creates a sample dataset.
*/
private XYDataset createDataset4(){

// create dataset 4...
BasicTimeSeries series4 = new BasicTimeSeries("330xi", Day.class);

series4.add(new Day(1, SerialDate.MARCH, 2002), 1285.3);
series4.add(new Day(2, SerialDate.MARCH, 2002), 1998.2);
series4.add(new Day(3, SerialDate.MARCH, 2002), 1653.2);
series4.add(new Day(4, SerialDate.MARCH, 2002), 1942.3);
series4.add(new Day(5, SerialDate.MARCH, 2002), 1853.5);
series4.add(new Day(6, SerialDate.MARCH, 2002), 1552.3);
series4.add(new Day(7, SerialDate.MARCH, 2002), 1332.0);
series4.add(new Day(8, SerialDate.MARCH, 2002), 1635.3);
series4.add(new Day(9, SerialDate.MARCH, 2002), 1998.2);
series4.add(new Day(10, SerialDate.MARCH, 2002), 1943.2);
series4.add(new Day(11, SerialDate.MARCH, 2002), 1643.9);
series4.add(new Day(12, SerialDate.MARCH, 2002), 1743.2);
series4.add(new Day(13, SerialDate.MARCH, 2002), 1495.3);
series4.add(new Day(14, SerialDate.MARCH, 2002), 1743.6);
series4.add(new Day(15, SerialDate.MARCH, 2002), 1500.7);
series4.add(new Day(16, SerialDate.MARCH, 2002), 1995.9);

return new TimeSeriesCollection(series4);

}
________________________________________________________


thanks again,
Hostos

Dave Gilbert

Re: reference to an object

Post by Dave Gilbert » Fri Nov 08, 2002 12:40 am

In the chartMouseClicked(...) method, you can do this:

ChartEntity entity = event.getEntity();
if (entity instanceof XYItemEntity) {
xyie = (XYItemEntity) entity;
int series = xyie.getSeries();
int item = xyie.getItem();
// now with the series and item indices, you can get values from the dataset...
// as long as you have a reference to the dataset somewhere.
}

Regards,

DG

Hotos Monegro

Re: reference to an object

Post by Hotos Monegro » Fri Nov 08, 2002 8:42 am

Hi,

1.What is the xyie. Should that be made into a reference for a XYItemEntity object?

2.What class is the instanceof method in?


thanks,
Hostos

Locked