Hello,
Is there a way to know if a user clicked on a point of a series (XYPlot rendering one or more TimeSeries) ? This is not as "easy" as it sounds since there should be some tolerance as well (if the points are only one pixels, it's quite difficult to click on them).
I'm using the chart inside a ChartComposite (for SWT) so I can register a ChartMouseListener on it but from there, I have no idea to check whether the user clicked on a point (and I don't even know if this is possible).
Thanks,
Cédric
Retrieve point under mouse click
-
- Posts: 7
- Joined: Wed Jul 03, 2013 8:53 am
- antibot: No, of course not.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Retrieve point under mouse click
If you use a ChartMouseListener, the ChartMouseEvent should have a reference to the ChartEntity that was under the mouse pointer. I don't know how well that works with the SWT ChartComposite, because it is a long time since I used SWT (that could possibly change in the coming months). And it varies a bit by renderer...if the points are small, then there isn't a big region for the "hotspot".
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Re: Retrieve point under mouse click
this is my code,
Code: Select all
ChartEntity ce = null;
ce = cp.getEntityForPoint(x, y);
if (ce instanceof XYItemEntity) {
XYItemEntity e = (XYItemEntity) ce;
XYDataset d = e.getDataset();
int s = e.getSeriesIndex();
int i = e.getItem();
Number valueX = d.getX(s, i);
Number valueY = d.getY(s, i);
}