Hit testing

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
swdev
Posts: 13
Joined: Sat Oct 14, 2006 1:01 pm

Hit testing

Post by swdev » Sat Oct 14, 2006 3:04 pm

Given an xy plot and a mouse click, how do I find out which point(s) are in a certain area around the click point? This is often know known as hit-testing and is related to my earlier question about which area an xy plot point occupies on the chart.

More generally, the manual seems to have nothing to say on the topic of user interaction with chart widgets. It would be useful to add a section on that.

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Mon Oct 16, 2006 7:36 am

I don't think there is such an automation in JFreeChart. Of course you could find out the coordinates of the event, transform the coordinates to real values and find out the nearest data by yourself.

But the common method is to trigger an action when the user clicks exactly on a data-item. This should be easy.

swdev
Posts: 13
Joined: Sat Oct 14, 2006 1:01 pm

Post by swdev » Mon Oct 16, 2006 11:32 am

I don't think there is such an automation in JFreeChart.
Every Swing widget for which it is relevant include such a method, e.g., JList.locationToIndex and JTable.rowAtPoint; it is not an unreasonable expectation.

In any case, what do you call a "data item"? How does one get its box?

swdev
Posts: 13
Joined: Sat Oct 14, 2006 1:01 pm

Post by swdev » Tue Oct 17, 2006 11:38 pm

I think I've found it: that would be the java2DToValue method of ValueAxis.

Locked