问题
I wanna users see more information in pie chart (example percent of data, shown in the chart below).
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,
)
回答1:
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
)
回答2:
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
来源:https://stackoverflow.com/questions/51445485/how-to-add-a-label-on-pie-chart-from-flutter