buildLegendItems method

  1. @override
List<LegendItem>? buildLegendItems(
  1. int index
)
override

Builds the legend item.

Implementation

@override
List<LegendItem>? buildLegendItems(int index) {
  final List<LegendItem> legendItems = <LegendItem>[];
  final int segmentsCount = segments.length;
  for (int i = 0; i < dataCount; i++) {
    final int legendIndex = dataCount - 1 - i;
    final ChartLegendItem legendItem = ChartLegendItem(
      text: xRawValues[legendIndex].toString(),
      iconType: toLegendShapeMarkerType(legendIconType, this),
      iconColor: effectiveColor(legendIndex),
      iconBorderWidth: legendIconBorderWidth(),
      series: this,
      seriesIndex: index,
      pointIndex: legendIndex,
      imageProvider: legendIconType == LegendIconType.image
          ? parent?.legend?.image
          : null,
      isToggled: i < segmentsCount && !segmentAt(i).isVisible,
      onTap: handleLegendItemTapped,
      onRender: _handleLegendItemCreated,
    );
    legendItems.add(legendItem);
  }
  return legendItems;
}