Reputation: 19415
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.
Upvotes: 2
Views: 2159
Reputation: 86
You have to add the type parameter of the PieChart.
Update:- Explanation
So in OP's case, instead of child: charts.PieChart(
use child: charts.PieChart<String>(
.
we use <String>
as type param because the series for chart is charts.Series<ChartEntity, String>
if series is charts.Series<ChartEntity, int>
then we should use <int>
as type parameter
Upvotes: 2
Reputation: 1484
I got with (is a barchart in my case):
defaultRenderer: new charts.BarRendererConfig(
fillPattern: charts.FillPatternType.solid,
//customRendererId: "id",
barRendererDecorator: charts.BarLabelDecorator(
labelPosition: charts.BarLabelPosition.auto,
labelAnchor: charts.BarLabelAnchor.middle),
cornerStrategy: const charts.ConstCornerStrategy(10),
),
Upvotes: 0
Reputation: 1
In my case the problem was the same, but resolved by putting an id
in defaultRenderer
, e.g.:
customRendererId: 'novoId'
Upvotes: 0