title | description | page_title | type | slug | position | tags | ticketid | res_type |
---|---|---|---|---|---|---|---|---|
Get Clicked Data Point in RadChartView |
Click data point visual in RadCartesianChart BarSeries. |
Execute action on mouse down on chart data point element |
how-to |
kb-chartview-howto-get-clicked-data-point |
0 |
clicked, datapoint, chart |
1470708 |
kb |
Product Version | 2020.2.513 |
Product | RadChartView for WPF |
How to get the clicked data point in RadCartesianChart.
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]({%slug radchartview-getting-started-data-point%}) 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.
{{region kb-chartview-howto-get-clicked-data-point-0}} 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);
}
}
{{endregion}}