A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
stefan__
- Posts: 4
- Joined: Thu Jan 07, 2010 4:17 pm
- antibot: No, of course not.
Post
by stefan__ » Thu Jan 07, 2010 4:26 pm
Im trying to fetch the TimeSeries in a chartMouseClicked event, however, event.getEntity() returns null:
Code: Select all
public void chartMouseClicked(ChartMouseEvent event) {
XYItemEntity entity = (XYItemEntity) event.getEntity();
XYDataset dataset = entity.getDataset();
int series = entity.getSeriesIndex();
}
Im using jfreechart-1.0.11, any ideas appreciated..
regards,
S
-
skunk
- Posts: 1087
- Joined: Thu Jun 02, 2005 10:14 pm
- Location: Brisbane, Australia
Post
by skunk » Thu Jan 07, 2010 5:48 pm
This works for me. Remember that the entity collection is only populated during rendering so it will be empty until the first time that the chart is plotted. What renderer are you using? Are you sure you are actually clicking "on" the item?
-
stefan__
- Posts: 4
- Joined: Thu Jan 07, 2010 4:17 pm
- antibot: No, of course not.
Post
by stefan__ » Thu Jan 07, 2010 6:33 pm
skunk, thanks for your reply. The crosshair seems to choose the closest timeseries, thus I exptected to get the timeseries the crosshair choose. Is there a way to do this?
Regards,
S
-
paradoxoff
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Post
by paradoxoff » Thu Jan 07, 2010 9:34 pm
stefan__ wrote:skunk, thanks for your reply. The crosshair seems to choose the closest timeseries, thus I exptected to get the timeseries the crosshair choose. Is there a way to do this?
A ChartMouseEvent will only return the ChartEntity "below" the mouse coordinates. It does not make an attempt to "look around" and find possible entities nearby. The lock on data items for crosshairs does only work because an XYPlot, tracks the coordinates for every rendered item and offers these coordinates to draw the cross hairs.
-
stefan__
- Posts: 4
- Joined: Thu Jan 07, 2010 4:17 pm
- antibot: No, of course not.
Post
by stefan__ » Thu Jan 07, 2010 9:43 pm
Ok, but if I have two items and click in the white space between, the crosshair choose the closest item, which is perfectly fine.
Question: can I in code find out which item the crosshair chose?
The crosshair obviously finds the item, so I would assume it should be able to tell me as well..?
regards,
Stefan