Selection

23 Sep 2020 / 3 minutes to read

SfChart supports selection that enables you to select a segment in a series or series itself.

Data Point Selection

You can select a data point by tapping on it. To enable the selection feature, you can use DataPointSelectionEnabled property.

  • c#
  • [C#]
    
    ColumnSeries columnSeries = new ColumnSeries();
    columnSeries.DataPointSelectionEnabled = true;

    Data point selection support in Xamarin.Android Chart

    Following properties are used to configure the selection feature,

  • c#
  • [C#]
    
    ColumnSeries columnSeries = new ColumnSeries();
    columnSeries.DataPointSelectionEnabled = true;
    columnSeries.SelectedDataPointIndex = 2;
    columnSeries.SelectedDataPointColor = Color.Red;

    Selecting data point and data point color support in Xamarin.Android Chart

    NOTE

    For Accumulation series like pie, doughnut, pyramid and funnel, when you select a data point, the corresponding legend item also will be selected.

    Series Selection

    Series selection is used in case of multiple series when you want to highlight a particular series. Series Selection can be enabled by setting EnableSeriesSelection property to true. The SeriesSelectionColor property is used to set the color to highlight the series.

  • c#
  • [C#]
    
    chart.EnableSeriesSelection = true;
    ...
    
    ColumnSeries series = new ColumnSeries();
    series.Color = Color.Rgb(174, 235, 231);
    ...
    
    ColumnSeries series1 = new ColumnSeries();
    series1.Color = Color.Rgb(211, 190, 229);
    ... 
    
    ColumnSeries series2 = new ColumnSeries();
    series2.Color = Color.Rgb(192, 216, 240);
    ...

    Series selection support in Xamarin.Android Chart

    To set the series selection color,

  • c#
  • [C#]
    
    chart.SeriesSelectionColor = Color.Rgb(0, 155, 247);

    Event

    SelectionChanging

    The SelectionChanging event of SfChart is used to subscribe the selection changing event and this is triggered before the data point is selected. You can restrict a data point from being selected, by canceling this event, by using Cancel property of the event argument. The argument contains the following information,

    SelectionChanged

    The SelectionChanged event of SfChart is used to subscribe the selection changed event and this triggered after a data point is selected. The argument contains the following information,