New to Telerik UI for WinForms? Start a free 30-day trial
Selection
Updated over 6 months ago
This help topic will demonstrate how you can make your charts more interactive by adding a selection behavior.
In order to utilize this behavior users simply have to add it to the chart's Controllers collection. For example:
Add Controller
C#
radChartView1.Controllers.Add(new ChartSelectionController());
radChartView1.SelectionMode = ChartSelectionMode.SingleDataPoint;
radChartView1.SelectedPointChanged += new ChartViewSelectedChangedEventHandler(radChartView1_SelectedPointChanged);
The ChartSelectionController will be added automatically if the SelectionMode property of RadChartView control is set to one of available options.
ChartSelectionMode
C#
radChartView1.SelectionMode = ChartSelectionMode.SingleDataPoint;
radChartView1.SelectionMode = ChartSelectionMode.MultipleDataPoints;
Here is a sample using PieSeries and multiple selection. When a slice is selected, it is being offsetted from the center:
Sliced Pie
C#
public ChartSelection()
{
InitializeComponent();
radChartView1.AreaType = ChartAreaType.Pie;
PieSeries pieSeries = new PieSeries();
pieSeries.ShowLabels = true;
pieSeries.PointSize = new SizeF(15, 15);
pieSeries.DataPoints.Add(new PieDataPoint(10));
pieSeries.DataPoints.Add(new PieDataPoint(5));
pieSeries.DataPoints.Add(new PieDataPoint(40));
pieSeries.DataPoints.Add(new PieDataPoint(22));
pieSeries.DataPoints.Add(new PieDataPoint(11));
pieSeries.DataPoints.Add(new PieDataPoint(20));
radChartView1.Series.Add(pieSeries);
radChartView1.Controllers.Add(new ChartSelectionController());
radChartView1.SelectionMode = ChartSelectionMode.MultipleDataPoints;
radChartView1.SelectedPointChanged += new ChartViewSelectedChangedEventHandler(radChartView1_SelectedPointChanged);
}
void radChartView1_SelectedPointChanged(object sender, ChartViewSelectedPointChangedEventArgs args)
{
if (args.NewSelectedPoint != null)
{
UpdateSelectedPoint(args.NewSelectedPoint);
}
if (args.OldSelectedPoint != null)
{
UpdateSelectedPoint(args.OldSelectedPoint);
}
}
void UpdateSelectedPoint(DataPoint point)
{
PieDataPoint pieDataPoint = point as PieDataPoint;
if (pieDataPoint != null)
{
if (pieDataPoint.IsSelected)
{
pieDataPoint.OffsetFromCenter = 0.1;
}
else
{
pieDataPoint.OffsetFromCenter = 0;
}
}
}
Figure 2: Sliced Pie
