如何从抖动中在饼图上添加标签?

时间:2018-07-20 15:05:55

标签: charts flutter

我想让用户在饼图中查看更多信息(数据百分比示例,如下表所示)。 enter image description here

我的代码用于显示饼图,我在Charts.Series中尝试了 displayName labelAccessorFn 之类的功能,但标签似乎仍然对我显示

module MyModule =
    type Dummy = Dummy

let myModule = typeof<MyModule.Dummy>.DeclaringType

2 个答案:

答案 0 :(得分:2)

我认为您缺少此提示

  new charts.Series<LinearSales, int>(
    id: 'Sales',
    domainFn: (LinearSales sales, _) => sales.year,
    measureFn: (LinearSales sales, _) => sales.sales,
    data: data,
    labelAccessorFn: (LinearSales row, _) => '${row.year}: ${row.sales}', //Add this
)

答案 1 :(得分:0)

对于其他遇到此问题的人:

要向图表添加标签,您需要像这样将arcRendererDecorators添加到ArcRendererConfig

  @override
  Widget build(BuildContext context) {
    return charts.PieChart(
        seriesList,
        animate: animate,
        defaultRenderer: new charts.ArcRendererConfig(
            arcWidth: 120,
            arcRendererDecorators: [  // <-- add this to the code 
              charts.ArcLabelDecorator() // <-- and this of course
            ]
        ));
  }
}

也不要忘记labelAccessorFn