How to change legend icon in pie chart, i am using charts_flutter 0.9.0

1,106

Thanks @Midhun MP for the hint, actually we need to use CustomSymbolRenderer instead of SymbolRenderer. The below code solved my issue

class IconRenderer extends charts.CustomSymbolRenderer {
  final IconData iconData;

  IconRenderer(this.iconData);

  @override
  Widget build(BuildContext context, {Size size, Color color, bool enabled}) {
    // Lighten the color if the symbol is not enabled
    // Example: If user has tapped on a Series deselecting it.
    if (!enabled) {
      color = color.withOpacity(0.26);
    }
    return new SizedBox.fromSize(
        size: size, child: new Icon(iconData, color: color, size: 12.0));
  }
}
Share:
1,106
Bala
Author by

Bala

Senior Software Engineer - Mobile Technology

Updated on December 19, 2022

Comments

  • Bala
    Bala over 1 year

    I am trying to change the legend icon from circle to rectangle for my pie chart. I am using the below lines for that but am getting error right away.

    defaultRenderer: new charts.ArcRendererConfig(
              symbolRenderer: new IconRenderer(Icons.cloud)
          ),
    

    I am getting the error (screenshot attached) please help me to change the default icon for the legend in pie chart.

    • Midhun MP
      Midhun MP about 4 years
      What is the error you are getting ?
    • Bala
      Bala about 4 years
      @MidhunMP even it is not compile, android studio itself popping the error as like this - defaultRenderer: new charts.ArcRendererConfig( symbolRenderer: new IconRenderer(Icons.cloud) ),
  • Bala
    Bala about 4 years
    Thanks @Midhun MP for the hint, actually we need to use CustomSymbolRenderer instead of SymbolRenderer.