Selection

1 Mar 20223 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, set EnableDataPointSelection property as True for series.

  • C#
  • SFColumnSeries series           = new SFColumnSeries ();
    
    series.EnableDataPointSelection = true;

    Data point selection support in Xamarin.iOS Chart

    Following properties are used to configure the selection feature,

  • C#
  • SFColumnSeries series           = new SFColumnSeries ();
    
    series.EnableDataPointSelection = true;
    
    series.SelectedDataPointIndex   = 2;
    
    series.SelectedDataPointColor   = UIColor.Red;

    Selecting data point and data point color support in Xamarin.iOS 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#
  • chart.EnableSeriesSelection = true;
    ...
    
    SFColumnSeries series = new SFColumnSeries();
    series.Color = UIColor.FromRGB(174, 235, 231);
    ...
    
    SFColumnSeries series1 = new SFColumnSeries();
    series1.Color = UIColor.FromRGB(211, 190, 229);
    ...
    
    SFColumnSeries series2 = new SFColumnSeries();
    series2.Color = UIColor.FromRGB(192, 216, 240);

    Series selection support in Xamarin.iOS Chart

    To set the series selection color,

  • C#
  • chart.SeriesSelectionColor = UIColor.FromRGB(0, 155, 247);

    Delegates

    We need to implement delegate to deal with the user interactions in chart for data point selection. In order to do this,you need to adopt the SFChartDelegate protocol through the class extension as shown below.

  • C#
  • public override void ViewDidLoad ()
    {
        chart.Delegate = new ChartDelegate ();
    }
    
    public class ChartDelegate : SFChartDelegate
    {
        public override void DidDataPointSelect (SFChart chart, SFChartSelectionInfo info)
        {
    
        }
    }

    WillDataPointSelect

    The WillDataPointSelect delegate is called when the series datapoint selection operation has been started, the argument includes the SFChartSelectionChangingInfo which is used to get the selection state. The argument contains the following information.

    DidDataPointSelect

    The DidDataPointSelect delegate is called when the series datapoint selection operation has been started, the argument includes the SFChartSelectionInfo which is used to get the selection state. The argument contains the following information.