3

I wanna users see more information in pie chart (example percent of data, shown in the chart below). enter image description here

My code is used show pie chart, i tried some function like displayName, labelAccessorFn in charts.Series but seem label still down show for me

  @override
  Widget build(BuildContext context) {
    return new charts.PieChart(seriesList,
        animate: animate,
        defaultRenderer: new charts.ArcRendererConfig(arcWidth: 60));
  }

  new charts.Series<LinearSales, int>(
    id: 'Sales',
    domainFn: (LinearSales sales, _) => sales.year,
    measureFn: (LinearSales sales, _) => sales.sales,
    data: data,
  )
Kamj Duong
  • 135
  • 1
  • 3
  • 10

2 Answers2

3

I think you're missing this:

  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
)
Andrew Takao
  • 105
  • 1
  • 13
  • Yeap. We will use **labelAccessorFn** to show label in pie chart – Kamj Duong Aug 21 '18 at 09:53
  • I wonder if there is an option which can help me crack this case - https://stackoverflow.com/questions/54649930/flutter-google-chart-gauge-place-label-within-center – Angel Todorov Feb 12 '19 at 20:06
3

For other people that come to this Question:

to add labels to the chart, you need to add the arcRendererDecorators to the ArcRendererConfig like this:

  @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
            ]
        ));
  }
}

don't forget also the labelAccessorFn

key
  • 1,334
  • 1
  • 19
  • 39