how to add text on pie chart slice in CustomPaint(Canvas) widget in flutter
298
To paint text in flutter using CustomPainter
you need to use TextSpan
and TextPainter
like so:
TextSpan span = new TextSpan(style: new TextStyle(color: Colors.blue[800]), text: yourText);
TextPainter tp = new TextPainter(text: span, textAlign: TextAlign.left, textDirection: TextDirection.ltr);
tp.layout();
tp.paint(canvas, new Offset(5.0, 5.0));
Author by
Hardik K
Updated on January 04, 2023Comments
-
Hardik K over 1 year
I have to add text on pie chart slices in canvas circle drawing and i have 3 slices in pie chart (cash/card/bill) and i want to set that text with their percentage on pie chart particular slice
note :- i completed drawing this chart now i only have to add text on slices
-
Yeasin Sheikh about 2 yearsCan you include your chart-code?
-
Hardik K about 2 yearschart image is included
-
Yeasin Sheikh about 2 yearsare you using any package like
pie_chart
? -
Hardik K about 2 yearsno, i drawing it on canvas
-
Yeasin Sheikh about 2 yearsCan you include that widget? also you can try those package.
-
-
Hardik K about 2 yearsi have to add text on particular slice of pie chart
-
TheUltimateOptimist about 2 yearsWell, then you just have to come up with some formula to calculate the right offset and plug it in the above code snippet.