Interactions

Listening to interactions on Pie Chart

The PieInteractionEvents class provides callbacks for all interactions happening on PieChart.

Look at the common Interactions guide to know about all the common interaction features.

Here we will see PieChart specific interaction details.

To start listening for interactions, provide an instance of PieInteractionEvents to the interactionEvents parameter on PieSeries.

PieChart(
    ...
    data: PieSeries(
        ...
        interactionEvents: PieInteractionEvents(
          isEnabled: true,
          onTap: (result) {
             ...
          },
          onDrag: (result) {
            // Update the data and call setState so that the chart 
            // will re-render based on new data.
            setState(() {
              _interactionIndex = result.sliceDataIndex;
            });
          }),
          ...
      )
  );
   

Pie Interaction Result

In addition to common parts described in Interactions, the PieIntractionResult has the details of the slice for which the interaction was triggered.

Every interaction callback for PieInteractionEvents will receive an instance of PieInteractionResult.

In addition to localOffset and TouchInteractionType, PieInteractionResult has

PropertiesDescription

slice

The SliceData that matches this interaction.

sliceDataIndex

The index of slice in PieSeries data.

Last updated