drawDataLabel method

void drawDataLabel(
  1. int index,
  2. Canvas canvas,
  3. String dataLabel,
  4. double pointX,
  5. double pointY,
  6. int angle,
  7. TextStyle style,
)

To customize each data labels.

Implementation

void drawDataLabel(
  int index,
  Canvas canvas,
  String dataLabel,
  double pointX,
  double pointY,
  int angle,
  TextStyle style,
) {
  if (!pointX.isNaN && !pointY.isNaN) {
    final TextSpan span = TextSpan(text: dataLabel, style: style);
    final TextPainter textPainter = TextPainter(
      text: span,
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr,
    );
    textPainter.layout();
    canvas.save();
    canvas.translate(
        pointX + textPainter.width / 2, pointY + textPainter.height / 2);
    canvas.rotate(degreeToRadian(angle));
    final Offset labelOffset =
        Offset(-textPainter.width / 2, -textPainter.height / 2);
    textPainter.paint(canvas, labelOffset);
    canvas.restore();
  }
}