JFreeChart: Getting items from XY-Charts by specifying XY-Coordinates

Hi,Imagine you have a simple xy chart. How can you get get the items from the chart by specifying the XY-Coordinates (axis coordinates!)? My purpose is to find out if for a given XY-Coordinate an Item is available on the chart or not?Any Idea?thanks
[277 byte] By [JavaParsa] at [2007-11-27 5:54:58]
# 1
Why don't you ask those who are concerned? http://www.jfree.org/phpBB2/viewforum.php?f=3
quittea at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 2
You can add a ChartMouseListener to the associated ChartPanel.
sabre150a at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 3

The JFreeChart forum has no answeres yet.

I am not doing that with listeners. I am sure there is a way you can get the

items from the chart.

Here is some more explenation:

...

ChartRenderingInfo chartrenderinginfo = chartpanel.getChartRenderingInfo();

EntityCollection entities = chartrenderinginfo.getEntityCollection();

//also does not work: item is always null?

item = (XYItemEntity)entities.getEntity(x,y);

//this also does not work...

//item = (XYItemEntity)chartpanel.getEntityForPoint(x, y);

//this also does not work

//Point p = chartpanel.translateJava2DToScreen(new Point(x,y));

//item = (XYItemEntity)entities.getEntity(p.getX(), p.getY());

if (item != null){

//this shall be entered if an item is found

//but never entered although I have data on the chart

}else{

System.out.println("item is null");

}

Any idea?

Message was edited by:

JavaPars

JavaParsa at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 4
Did you read my earlier response?
sabre150a at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 5
yes, i did. but i guess i don't get your idea. can you please explain?
JavaParsa at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 6
Add a ChartMouseListener to the ChartPanel and then look at the events when you mouse click on the chart.Message was edited by: sabre150
sabre150a at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 7

Ok, but this is not exactly what i wanted. here is some detailed explanation:

The user can choose some of the items displayed on the chart by making a right click and than dragging the mouse to some other point. When dooing this a rect is drawn, so the user sees what will be selected. So what I want is to find out which items are within the selection area. My idea to find this out is:

1. get all the possible xy coordinates that are in this area

2. for all of these coordinates try to find out if an item is on the achart or not (see sourcecode above)

does this help to understand what I am trying to do? As you see I do not need the listener you mentioned...

JavaParsa at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 8
Most of which can be done by adding a ChartMouseListener to the ChartPanel! Using event.getEntity() will tell you which 'points' you are working with.
sabre150a at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 9

yes, sure. but only if I click on ONE item. How about if you do not click on an item? Again: The user selects ALL items he wants by clicking+dragging the mouse. Any idea? I have a workaround for my problem. But I I hope there is a way how one can get items from a chart by specifying the xy coordinates. If this is not possible, than JFreeChart might shall make this possible. I believe this is a reasonable requirement...

JavaParsa at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...
# 10
Most chart packages I have worked with have had a method to convert screen coordinates to dataset coordinates but I can't find this in JFreeChart - I bet it exists though! Sorry I can't help.
sabre150a at 2007-7-12 15:50:01 > top of Java-index,Java Essentials,Java Programming...