menu

MAUI Toolkit

  • User Guide
  • Demos
  • Support
Class ChartSelectionBehavior - MAUI-ToolKit API Reference | Syncfusion

    Show / Hide Table of Contents

    Class ChartSelectionBehavior

    Provides the base functionality for selection behaviors in charts.

    Inheritance
    System.Object
    ChartBehavior
    ChartSelectionBehavior
    DataPointSelectionBehavior
    SeriesSelectionBehavior
    Inherited Members
    ChartBehavior.OnTouchDown(ChartBase, Single, Single)
    ChartBehavior.OnTouchMove(ChartBase, Single, Single)
    ChartBehavior.OnTouchUp(ChartBase, Single, Single)
    Namespace: Syncfusion.Maui.Toolkit.Charts
    Assembly: Syncfusion.Maui.Toolkit.dll
    Syntax
    public abstract class ChartSelectionBehavior : ChartBehavior, IParentThemeElement, IThemeElement
    Remarks

    The ChartSelectionBehavior class serves as the base class for specialized selection behaviors, such as DataPointSelectionBehavior and SeriesSelectionBehavior. It provides the core methods and properties required to handle selection logic in chart elements.

    Constructors

    ChartSelectionBehavior()

    Initializes a new instance of the ChartSelectionBehavior class.

    Declaration
    public ChartSelectionBehavior()

    Fields

    SelectedIndexesProperty

    Identifies the SelectedIndexes bindable property.

    Declaration
    public static readonly BindableProperty SelectedIndexesProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The identifier for the SelectedIndexes bindable property determines the indexes of the selected chart segments.

    SelectedIndexProperty

    Identifies the SelectedIndex bindable property.

    Declaration
    public static readonly BindableProperty SelectedIndexProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The identifier for the SelectedIndex bindable property determines the index of the selected chart segment.

    SelectionBrushProperty

    Identifies the SelectionBrush bindable property.

    Declaration
    public static readonly BindableProperty SelectionBrushProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The identifier for the SelectionBrush bindable property determines the brush used for the selected chart segments.

    TypeProperty

    Identifies the Type bindable property.

    Declaration
    public static readonly BindableProperty TypeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The identifier for the Type bindable property determines the type of selection behavior for the chart.

    Properties

    SelectedIndex

    Gets or sets the index of segment or series to be selected in selection behavior.

    Declaration
    public int SelectedIndex { get; set; }
    Property Value
    Type Description
    System.Int32

    This property takes System.Int32 value and its default value is -1.

    Remarks

    This property value is used only when Type is set to Single or SingleDeselect.

    Examples
    • MainPage.xaml
    • MainPage.xaml.cs
    <chart:SfCircularChart>
    
            <!--omitted for brevity-->
    
            <chart:PieSeries ItemsSource="{Binding Data}"
                             XBindingPath="XValue"
                             YBindingPath="YValue">
                <chart:PieSeries.SelectionBehavior>
                    <chart:DataPointSelectionBehavior SelectedIndex="3" SelectionBrush = "Red" />
            </chart:PieSeries.SelectionBehavior>
            </chart:PieSeries>
    
    </chart:SfCircularChart>
     SfCircularChart chart = new SfCircularChart();
     ViewModel viewModel = new ViewModel();
    
     PieSeries series = new PieSeries()
     {
        ItemsSource = viewModel.Data,
        XBindingPath = "XValue",
        YBindingPath = "YValue",
     };
    
     series.SelectionBehavior = new DataPointSelectionBehavior()
     {
         SelectedIndex = 3,
         SelectionBrush = new SolidColorBrush(Colors.Red),
     };
    
     chart.Series.Add(series);

    SelectedIndexes

    Gets or sets the list of segments or series to be selected in selection behavior.

    Declaration
    public List<int> SelectedIndexes { get; set; }
    Property Value
    Type Description
    System.Collections.Generic.List<System.Int32>

    This property takes the list of System.Collections.Generic.List<> where System.Int32 represents the integer values and its default value is null.

    Remarks

    This property value is used only when Type is set to Multiple.

    Examples
    • MainPage.xaml
    • MainPage.xaml.cs
    <chart:SfCircularChart>
    
            <!--omitted for brevity-->
    
            <chart:PieSeries ItemsSource="{Binding Data}"
                             XBindingPath="XValue"
                             YBindingPath="YValue">
                <chart:PieSeries.SelectionBehavior>
                    <chart:DataPointSelectionBehavior Type="Multiple" SelectedIndexes="{Binding indexes}" SelectionBrush = "Red" />
            </chart:PieSeries.SelectionBehavior>
            </chart:PieSeries>
    
    </chart:SfCircularChart>
     SfCircularChart chart = new SfCircularChart();
     ViewModel viewModel = new ViewModel();
    
     PieSeries series = new PieSeries()
     {
        ItemsSource = viewModel.Data,
        XBindingPath = "XValue",
        YBindingPath = "YValue",
     };
    
     List<int> indexes = new List<int>() { 1, 3, 5 };
     series.SelectionBehavior = new DataPointSelectionBehavior()
     {
         Type = ChartSelectionType.Multiple,
         SelectedIndexes= indexes,
         SelectionBrush = new SolidColorBrush(Colors.Red),
     };
    
     chart.Series.Add(series);

    SelectionBrush

    Gets or sets the selection brush color for selection behavior.

    Declaration
    public Brush SelectionBrush { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.Controls.Brush

    This property takes Microsoft.Maui.Controls.Brush value and its default value is null.

    Examples
    • MainPage.xaml
    • MainPage.xaml.cs
    <chart:SfCircularChart>
    
            <!--omitted for brevity-->
    
            <chart:PieSeries ItemsSource="{Binding Data}"
                             XBindingPath="XValue"
                             YBindingPath="YValue">
                <chart:PieSeries.SelectionBehavior>
                    <chart:DataPointSelectionBehavior SelectionBrush = "Red" />
            </chart:PieSeries.SelectionBehavior>
            </chart:PieSeries>
    
    </chart:SfCircularChart>
     SfCircularChart chart = new SfCircularChart();
     ViewModel viewModel = new ViewModel();
    
     PieSeries series = new PieSeries()
     {
        ItemsSource = viewModel.Data,
        XBindingPath = "XValue",
        YBindingPath = "YValue",
     };
    
     series.SelectionBehavior = new DataPointSelectionBehavior()
     {
         SelectionBrush = new SolidColorBrush(Colors.Red),
     };
    
     chart.Series.Add(series);

    Type

    Gets or sets the selection mode for selection behavior.

    Declaration
    public ChartSelectionType Type { get; set; }
    Property Value
    Type Description
    ChartSelectionType

    This property takes ChartSelectionType as value and its default value is Single.

    Examples
    • MainPage.xaml
    • MainPage.xaml.cs
    <chart:SfCircularChart>
    
            <!--omitted for brevity-->
    
            <chart:PieSeries ItemsSource="{Binding Data}"
                             XBindingPath="XValue"
                             YBindingPath="YValue">
                <chart:PieSeries.SelectionBehavior>
                    <chart:DataPointSelectionBehavior Type="Multiple" SelectionBrush = "Red" />
            </chart:PieSeries.SelectionBehavior>
            </chart:PieSeries>
    
    </chart:SfCircularChart>
     SfCircularChart chart = new SfCircularChart();
     ViewModel viewModel = new ViewModel();
    
     PieSeries series = new PieSeries()
     {
        ItemsSource = viewModel.Data,
        XBindingPath = "XValue",
        YBindingPath = "YValue",
     };
    
     series.SelectionBehavior = new DataPointSelectionBehavior()
     {
         Type = ChartSelectionType.Multiple,
         SelectionBrush = new SolidColorBrush(Colors.Red),
     };
    
     chart.Series.Add(series);

    Methods

    ClearSelection()

    Resets the current selection behavior by removing all values from SelectedIndex and SelectedIndexes.

    Declaration
    public void ClearSelection()

    Events

    SelectionChanged

    This event is triggered after a clicked series segment or sets the value for SelectedIndex or SelectedIndexes properties. It provides information about the selection change, including the currently selected index and the previously selected index.

    Declaration
    public event EventHandler<ChartSelectionChangedEventArgs> SelectionChanged
    Event Type
    Type
    System.EventHandler<ChartSelectionChangedEventArgs>

    SelectionChanging

    Occurs when the user clicks on the series segment or sets the value for SelectedIndex or SelectedIndexes properties. This event is triggered before a segment or series is selected.

    Declaration
    public event EventHandler<ChartSelectionChangingEventArgs> SelectionChanging
    Event Type
    Type
    System.EventHandler<ChartSelectionChangingEventArgs>
    Remarks

    Restrict a data point from being selected, by canceling this event, by setting System.ComponentModel.CancelEventArgs.Cancel property to true in the event argument.

    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved