Selection in .NET MAUI Chart

The SfCircularChart provides selection behavior support, which allows you to select or highlight a segment (data points) in a series using the DataPointSelectionBehavior.

Enable selection

To enable the data point selection, create an instance of the series SelectionBehavior property.

<chart:SfCircularChart>
    <chart:SfCircularChart.Series>
        <chart:DoughnutSeries>
            <chart:DoughnutSeries.SelectionBehavior>
                <chart:DataPointSelectionBehavior SelectionBrush="#314A6E"/>
            </chart:DoughnutSeries.SelectionBehavior>
        </chart:DoughnutSeries>
    </chart:SfCircularChart.Series>
</chart:SfCircularChart>
SfCircularChart chart = new SfCircularChart();

DataPointSelectionBehavior selection = new DataPointSelectionBehavior();
selection.SelectionBrush="#314A6E";

DoughnutSeries series = new DoughnutSeries();
series.SelectionBehavior = selection;
chart.Series.Add(series);

Behavior customization

The following properties are used to customize the ChartSelectionBehavior:

  • Type - Gets or sets the ChartSelectionType for the selection behavior.
    Chart selection types:
    • Single - The user can select only one item at a time
    • SingleDeselect - The user can select and deselect only one item at a time.
    • Multiple - The user can select and deselect multiple items at a time.
    • None - The user can’t select any item.
  • SelectionBrush - Gets or sets the brush color for the selection.
  • SelectedIndex - Gets or sets the value of the index to be selected.
  • SelectedIndexes - Gets or sets the list of indexes to be selected.
  • ClearSelection - Used to reset all the selection customizations to default.

Events

The following selection events are available in the ChartSelectionBehavior.

SelectionChanging

The SelectionChanging event occurs before the data point is being selected. This is a cancelable event. The following properties are contained in the event arguments:

  • NewIndexes - Gets the index of the selected data point.
  • OldIndexes - Gets the index of the deselected data point.
  • Cancel - Gets or sets a value indicating whether to continue the selection.

SelectionChanged

The SelectionChanged event occurs after a data point has been selected. The following properties are contained in the event arguments:

  • NewIndexes - Gets the index of the selected data point.
  • OldIndexes - Gets the index of the deselected data point.