ChartControl.SelectionMode Property
Gets or sets a value which specifies how the chart elements are selected.
Namespace: DevExpress.XtraCharts
Assembly: DevExpress.XtraCharts.v18.2.UI.dll
Declaration
public ElementSelectionMode SelectionMode { get; set; }
Public Property SelectionMode As ElementSelectionMode
Property Value
Type | Description |
---|---|
ElementSelectionMode | An ElementSelectionMode enumeration member specifying the chart's selection behavior. |
Remarks
Note, that the chart selection is not cleared when this property is set to None. To clear the selection, call the ChartControl.ClearSelection method.
Examples
This example shows how to obtain currently selected series points and show them in another chart. To do this, the ChartControl.SelectedItemsChanged event should be used.
In this example, you can choose the selection behavior (Single, Multiple or Extended) from the Selection Mode combo box. When any country is selected in the pie chart, you can see the population dynamics for each country in the bar chart. To cancel pie segment selection, choose None in the Selection Mode combo box.
In addition, this example demonstrates how to colorize each bar series point in the pie specific color using the ChartControl.CustomDrawSeriesPoint event.
NOTE
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-perform-an-action-when-series-points-are-selected-t182608
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace ChartSelection {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
PaletteEntry[] paletteEntries;
private void Form1_Load(object sender, EventArgs e) {
// Specify selection mode for the Pie chart.
this.cbSelectionMode.Properties.Items.AddRange(Enum.GetValues(typeof(ElementSelectionMode)));
this.cbSelectionMode.SelectedIndex = 2;
pieChart.SeriesSelectionMode = SeriesSelectionMode.Point;
// Handle the SelectedItemsChanged event for the Pie chart.
pieChart.SelectedItemsChanged += pieChart_SelectedItemsChanged;
// Handle the CustomDrawSeriesPoint event for the Bar chart.
barChart.CustomDrawSeriesPoint += barChart_CustomDrawSeriesPoint;
// Get palette entries of the pie chart.
paletteEntries = pieChart.GetPaletteEntries(pieChart.Series[0].Points.Count);
}
private void cbSelectionMode_SelectedIndexChanged(object sender, EventArgs e) {
pieChart.SelectionMode = (ElementSelectionMode)this.cbSelectionMode.SelectedItem;
}
private void pieChart_SelectedItemsChanged(object sender, SelectedItemsChangedEventArgs e) {
barChart.Series[0].Points.Clear();
foreach (SeriesPoint piePoint in pieChart.SelectedItems) {
SeriesPoint barPoint = new SeriesPoint(piePoint.Argument, piePoint.Values[0]);
barPoint.Tag = pieChart.Series[0].Points.IndexOf(piePoint);
barChart.Series[0].Points.Add(barPoint);
}
}
private void barChart_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) {
BarDrawOptions barOptions = e.SeriesDrawOptions as BarDrawOptions;
int colorIndex = (int)e.SeriesPoint.Tag;
barOptions.Color = paletteEntries[colorIndex].Color;
}
}
}