google / charts

https://pub.dev/packages/charts_flutter
Apache License 2.0
2.8k stars 1.2k forks source link

Cannot Render Pie Chart #733

Closed rkj1998 closed 2 years ago

rkj1998 commented 2 years ago

I am trying to create a pie chart with custom data.

Following is a snippet from my code.

` List<charts.Series<LinearSales, int>> _createSampleData() { final data = [ new LinearSales(0, resultData['correct'],Colors.green), new LinearSales(1, resultData['incorrect'],Colors.red), new LinearSales(2, resultData['totalquestions']-(resultData['correct']+resultData['incorrect']),Colors.black12), ];

return [
  new charts.Series<LinearSales, int>(
      id: 'Sales',
      domainFn: (LinearSales sales, _) => sales.year,
      measureFn: (LinearSales sales, _) => sales.sales,
      data: data,
      colorFn: (LinearSales sales, __) => charts.ColorUtil.fromDartColor(sales.mycolor)
  )
];

}`

@override Widget build(BuildContext context) { return Container( child: charts.PieChart(_createSampleData(), defaultRenderer: new charts.ArcRendererConfig(arcWidth: 20)), ); }

I am continuously getting an error type 'List<ArcRendererElement>' is not a subtype of type 'List<ArcRendererElement>?' in type cast RenderBox was not laid out: ChartContainerRenderObject#3f47a NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

Can anyone help me fix this ?