This is my JSON data:
dashboardResult:{
"new_call":18,
"overdue_calls":0,
"completed_calls":2523
}
Now I want to show these 3 json object value in % in PieChart:see here is piechar This is my code to show PieChart:
Widget onTimeComp(BuildContext context) {
return Container(
margin: EdgeInsets.only(left: 10, right:10, top:10, bottom:5),
padding: EdgeInsets.only(top: 15,bottom: 25,left: 15,right: 0),
color: Colors.lightBlue[100],
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
child:Text("On-time Completion",style: TextStyle(color: Colors.lightBlue,fontWeight: FontWeight.bold)),
),
],
),
SizedBox(height: 20,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
child: PieChart(
dataMap: dataMap,
animationDuration: Duration(milliseconds: 800),
chartLegendSpacing: 32.0,
chartRadius: MediaQuery.of(context).size.width / 2.7,
showChartValuesInPercentage: true,
showChartValues: true,
showChartValuesOutside: false,
chartValueBackgroundColor: Colors.grey[200],
colorList: colorList,
showLegends: true,
legendPosition: LegendPosition.right,
decimalPlaces: 1,
showChartValueLabel: true,
initialAngle: 0,
chartValueStyle: defaultChartValueStyle.copyWith(color: Colors.blueGrey[900].withOpacity(0.9)),
chartType: ChartType.disc,
)
),
],
),
]
),
);
}
I called this method in body():
body: Stack(
children: <Widget>[
ListView(
children: <Widget>[
onTimeComp(context),
],
),
],
),
),
here is intState method:
@override
void initState() {
super.initState();
dataMap.putIfAbsent("Complete", () =>2522 );
dataMap.putIfAbsent("New Calls", () => 19);
dataMap.putIfAbsent("Overdue", () => 0);
}
Now how to show json objects value?
dataMap.putIfAbsent("Complete", () =>new_call);
dataMap.putIfAbsent("New Calls", () => overdue_calls);
dataMap.putIfAbsent("Overdue", () => completed_calls);
See Question&Answers more detail:os