Bar Interactions

Listening to interactions on Bar Chart

The BarInteractionEvents class provides callbacks for all interactions happening on BarChart.

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

Here we will see BarChart specific interaction details.

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

BarChart(
    ...
    data: BarSeries(
        ...
        interactionEvents: BarInteractionEvents(
          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.barGroupIndex;
              _barIndex = result.barDataIndex;
            });
          }),
          ...
      )
  );
   

Bar Interaction Events

BarInteractionEvents has all the common parts described in Interactions section.

In addition to all the common callbacks and properties, BarInteractionEvents has the following:

Bar Interaction Result

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

Every interaction callback for BarInteractionEvents will receive an instance of BarInteractionResult.

In addition to localOffset and TouchInteractionType, BarInteractionResult has

PropertiesDescription

barGroup

The BarGroup that matched this interaction.

barGroupIndex

Index of the barGroup in the BarSeries.

barData

The BarData in the barGroup that matched this interaction.

barDataIndex

The index of barData in the barGroup.

Last updated