简体   繁体   English

如何在 flutter 中的 CustomPaint(Canvas) 小部件中的饼图切片上添加文本

[英]how to add text on pie chart slice in CustomPaint(Canvas) widget in flutter

在此处输入图像描述

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我必须在 canvas 圆形绘图中的饼图切片上添加文本,我在饼图(现金/卡/账单)中有 3 个切片,我想在饼图特定切片上设置该文本及其百分比

note:- i completed drawing this chart now i only have to add text on slices注意:- 我现在已完成绘制此图表我只需要在切片上添加文本

To paint text in flutter using CustomPainter you need to use TextSpan and TextPainter like so:要使用CustomPainter在 flutter 中绘制文本,您需要像这样使用TextSpanTextPainter

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM