How to get a point from chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
LucaSirri
Posts: 15
Joined: Tue Sep 16, 2008 11:48 am

How to get a point from chart

Post by LucaSirri » Tue Nov 04, 2008 4:35 pm

I have a little problem ... :(

I have a point in screen coordinates

Code: Select all

Point p = getMousePosition();
There is a way to know if this point is in a dataset chart ?

Image

LucaSirri
Posts: 15
Joined: Tue Sep 16, 2008 11:48 am

Post by LucaSirri » Tue Nov 04, 2008 5:11 pm

Ok I find a way :

Code: Select all

    	Point p = getMousePosition();    	
    	XYItemEntity entity = null;
    	entity = (XYItemEntity) chartPanel.getEntityForPoint(p.x,p.y);    	    
    	System.out.println("p :" + p);
    	System.out.println("x :" + chartPanel.getChart().getXYPlot().getDataset(entity.getSeriesIndex()).getXValue(entity.getSeriesIndex(), entity.getItem()));
    	System.out.println("y :" + chartPanel.getChart().getXYPlot().getDataset(entity.getSeriesIndex()).getYValue(entity.getSeriesIndex(), entity.getItem()));

Locked