Chart Displays as expected with the following PieChart widget.
class ABCPieChart extends StatefulWidget {
@override
_ABCPieChartState createState() => _ABCPieChartState();
}
class _TABCPieChartState extends State<ABCPieChart> {
List<charts.Series<ChartEntity, String>> _entities = List();
_initData() {
var values = [
ChartEntity("Food", 30, Colors.greenAccent),
ChartEntity("Clothing", 30, Colors.cyan),
ChartEntity("Fashion", 20, Colors.red),
ChartEntity("Gadgets", 20, Colors.blue),
];
_entities.add(charts.Series(
data: values,
domainFn: (ChartEntity entity, _) => entity.title,
measureFn: (ChartEntity entity, _) => entity.percentage,
colorFn: (ChartEntity entity, _) =>
charts.ColorUtil.fromDartColor(entity.color),
id: "random chart",
labelAccessorFn: (ChartEntity entity, _) => "${entity.percentage}"));
}
@override
void initState() {
super.initState();
_entities = List<charts.Series<ChartEntity, String>>();
_initData();
}
@override
Widget build(BuildContext context) {
return Container(
height: 400.0,
width: 400,
child: charts.PieChart(
_entities,
animate: true,
animationDuration: Duration(milliseconds: 500),
),
);
}
}
But when I try to customize it to a donut shape, Even after adding a very basic
defaultRenderer
, the chart is not rendered in the screen anymore.
class ABCPieChart extends StatefulWidget {
@override
_ABCPieChartState createState() => _ABCPieChartState();
}
class _TABCPieChartState extends State<ABCPieChart> {
List<charts.Series<ChartEntity, String>> _entities = List();
_initData() {
var values = [
ChartEntity("Food", 30, Colors.greenAccent),
ChartEntity("Clothing", 30, Colors.cyan),
ChartEntity("Fashion", 20, Colors.red),
ChartEntity("Gadgets", 20, Colors.blue),
];
_entities.add(charts.Series(
data: values,
domainFn: (ChartEntity entity, _) => entity.title,
measureFn: (ChartEntity entity, _) => entity.percentage,
colorFn: (ChartEntity entity, _) =>
charts.ColorUtil.fromDartColor(entity.color),
id: "random chart",
labelAccessorFn: (ChartEntity entity, _) => "${entity.percentage}"));
}
@override
void initState() {
super.initState();
_entities = List<charts.Series<ChartEntity, String>>();
_initData();
}
@override
Widget build(BuildContext context) {
return Container(
height: 400.0,
width: 400,
child: charts.PieChart(
_entities,
animate: true,
animationDuration: Duration(milliseconds: 500),
defaultRenderer: charts.ArcRendererConfig(),
),
);
}
}
Even when I copy and paste the code from google sample here, It does not render. (Neither in hotreload, nor in Hotrestart, nor Coldrestart)
This issue is only withPieChart and ArcRendererConfig.
BarChart
with BarRendererConfig
works fine
I think it might be setup issue or might have missed a very small but crucial stuff, does anyone have any idea what might have been wrong?
I have cross-posted this question in Github here, with a hope that this question will be seen by any disjoint set of audience in GitHub and SO(I am one of them). Not for spamming or annoying anybody.