buildLegendItems method

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

Builds the legend item.

Implementation

@override
List<LegendItem>? buildLegendItems(int index) {
  final num sumOfY = circularYValues
      .reduce((num value, num element) => value + element.abs());
  const double pointStartAngle = -90;
  final List<LegendItem> legendItems = <LegendItem>[];
  final int segmentsCount = segments.length;
  for (int i = 0; i < dataCount; i++) {
    double degree = circularYValues[i] / (maximumValue ?? sumOfY);
    degree = (degree > 1 ? 1 : degree) * fullAngle;
    final double pointEndAngle = pointStartAngle + degree;

    final ChartLegendItem legendItem = ChartLegendItem(
      text: circularXValues[i].toString(),
      iconType: toLegendShapeMarkerType(legendIconType, this),
      iconColor: effectiveColor(i),
      shader: _legendIconShaders(i),
      series: this,
      seriesIndex: index,
      pointIndex: i,
      startAngle: pointStartAngle,
      endAngle: pointEndAngle,
      degree: degree,
      iconBorderColor: trackColor,
      iconBorderWidth: legendIconBorderWidth(),
      imageProvider: legendIconType == LegendIconType.image
          ? parent?.legend?.image
          : null,
      isToggled: i < segmentsCount && !segmentAt(i).isVisible,
      onTap: handleLegendItemTapped,
      onRender: _handleLegendItemCreated,
    );
    legendItems.add(legendItem);
  }
  return legendItems;
}