selectDataPoints method

void selectDataPoints(
  1. int pointIndex, [
  2. int seriesIndex = 0
])

/Selects or deselects the specified data point in the series.

The following are the arguments to be passed.

  • pointIndex - index of the data point that needs to be selected.
  • seriesIndex - index of the series in which the data point is selected.

Where the pointIndex is a required argument and seriesIndex is an optional argument. By default, 0 will be considered as the series index. Thus it will take effect on the first series if no value is specified.

For Circular, Pyramid and Funnel charts, seriesIndex should always be 0, as it has only one series.

If the specified data point is already selected, it will be deselected, else it will be selected. Selection type and multi-selection functionality is also applicable for this, but it is based on the API values specified in ChartSelectionBehavior.

Note: - Even though, the enable property in ChartSelectionBehavior is set to false, this method will work.

Widget build(BuildContext context) {
selection = SelectionSettings(enable: true);
chart = SfCartesianChart(series:getChartData);
  return Scaffold(
     child: Column(
       children: <Widget>[
      FlatButton(
           child: Text('Select'),
           onPressed: select),
         Container(child: chart)
       ]));
}
 void select() {
    selection.selectionIndex(1, 0);
}
```dart

Implementation

void selectDataPoints(int pointIndex, [int seriesIndex = 0]) {
  final dynamic seriesRenderer =
      _chartState._chartSeries.visibleSeriesRenderers[seriesIndex];
  final SelectionBehaviorRenderer selectionBehaviorRenderer =
      seriesRenderer._selectionBehaviorRenderer;
  selectionBehaviorRenderer._selectionRenderer
      ?.selectDataPoints(pointIndex, seriesIndex);
}