New to Telerik UI for WPF? Download free 30-day trial

Get Clicked Data Point in RadChartView

Environment

Product Version 2020.2.513
Product RadChartView for WPF

Description

How to get the clicked data point in RadCartesianChart.

Solution

To get the clicked data point, you can use the MouseLeftButtonDown event of RadCartesianChart. In the event handler, get the mouse position and check if the LayoutSlot property of any DataPoint object contains the position.

The following example shows this approach with BarSeries, but you can apply this with any series that has its default visual element shown.

private void RadCartesianChart_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) 
{ 
    var chart = (RadCartesianChart)sender; 
    CategoricalDataPoint clickedDataPoint = null; 
    var mousePosition = e.GetPosition(chart); 
    foreach (BarSeries series in chart.Series) 
    { 
        foreach (var dp in series.DataPoints) 
        { 
            if (dp.LayoutSlot.Contains(mousePosition.X, mousePosition.Y)) 
            { 
                clickedDataPoint = dp; 
            } 
        } 
    } 
 
    if (clickedDataPoint != null) 
    { 
        var clickedDataItem = clickedDataPoint.DataItem; 
        var clickedDataPointSeries = (BarSeries)clickedDataPoint.Presenter; 
        var clickedVisual = clickedDataPointSeries.GetDataPointVisual(clickedDataPoint); 
    }         
} 
In this article