2

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),
      ),
    );
  }
}

Without Default renderer 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(),

      ),
    );
  }
}

After adding a defaultRenderer

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 BarRendererConfigworks 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.

WhiteHat
  • 59,912
  • 7
  • 51
  • 133
erluxman
  • 18,155
  • 20
  • 92
  • 126

4 Answers4

2

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

rahul maindargi
  • 5,359
  • 2
  • 16
  • 23
0

In my case the problem was the same, but resolved by putting an id in defaultRenderer, e.g.:

customRendererId: 'novoId'
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
0

Here a solution possibly

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),
  ),
Pedro Molina
  • 1,101
  • 12
  • 12
-1

simply remove the defaultRenderer and it will work