Programming User Interaction > Returning Coordinate Values > Picking Data Points |
To determine the closest data point to a set of pixel coordinates, call CoordToDataIndex:
Dim Row As Long
Dim Column As Long
Dim Distance As Long
Dim Region As Integer
With Chart2D1.ChartGroups(1)
Region = CoordToDataIndex 225, 92, Row, Column
End With
CoordToDataIndex returns the row and column of the closest data point, and also returns the distance in pixels between the pixel coordinates and the point. CoordToDataIndex returns, as its return value, the region of the chart in which the pixel coordinates are located. This region is represented as a region constant. When the returned region is oc2dRegionInLegend, the returned point value is also set to oc2dRegionInLegend, and the returned series is the closest element in the legend.