Created
May 31, 2021 16:20
-
-
Save Indy9000/47490fb274dd8c579f435d6748fd9707 to your computer and use it in GitHub Desktop.
animated-donut-chart-03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DonutChartPainter extends CustomPainter { | |
final List<DataItem> dataset; | |
DonutChartPainter(this.dataset); | |
@override | |
void paint(Canvas canvas, Size size) { | |
final c = Offset(size.width / 2.0, size.height / 2.0); | |
final radius = size.width * 0.9; | |
final rect = Rect.fromCenter(center: c, width: radius, height: radius); | |
final fullAngle = 360.0; | |
var startAngle = 0.0; | |
//draw sectors | |
dataset.forEach((di) { | |
final sweepAngle = di.value * fullAngle * pi / 180.0; | |
drawSector(canvas, di, rect, startAngle, sweepAngle); | |
drawLabels(canvas, c, radius, startAngle, sweepAngle, di.label); | |
startAngle += sweepAngle; | |
}); | |
// draw the middle | |
canvas.drawCircle(c, radius * 0.3, midPaint); | |
// draw title | |
drawTextCentered(canvas, c, "Favourite\nMovie\nGenres", | |
textFieldTextBigStyle, radius * 0.6, (Size sz) {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment