MindFusion.Charting for Silverlight Programmer's Guide
Hit testing

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#  Copy Code

private void barChart1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    Point p = e.GetPosition(barChart1);
    List<ChartElement> list = barChart1.HitTest(p);

    foreach (ChartElement element in list)
    {
        if (element is Bar)
        {
            Bar bar = element as Bar;
            int seriesIndex = bar.SeriesIndex;
            int dataIndex = bar.BarIndex;
            MessageBox.Show(seriesIndex.ToString() + " " + dataIndex.ToString());
        }
    }
 }

VB.NET  Copy Code

Private Sub barChart1_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs)
    Dim p As Point = e.GetPosition(barChart1)
    Dim list As List(Of ChartElement) = barChart1.HitTest(p)

    For Each element As ChartElement In list
        If TypeOf element Is Bar Then
            Dim bar As Bar = TryCast(element, Bar)
            Dim seriesIndex As Integer = bar.SeriesIndex
            Dim dataIndex As Integer = bar.BarIndex
            MessageBox.Show(seriesIndex.ToString() & " " & dataIndex.ToString())
        End If
    Next
End Sub