Hit testing is done with the HitTest method. You must give a point for which to test and the method will return a list of the ChartElement objects that contain this point. The ChartElement can be either Bar, Line, Scatter or PiePiece. Each ChartElement has Index and SeriesIndex properties, which allow you to recognize the series that this chart element belongs to.
The location of the data that the ChartElement represents in the data list for the series can be get with the Bar.BarIndex, Scatter.ScatterIndex, PiePiece.PieceIndex and Line.Points properties.
The following code tests which bar the user has clicked. It uses the MouseLeftButtonUp event:
C#
![]() |
---|
private void barChart1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) |
VB.NET
![]() |
---|
Private Sub barChart1_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs) |