Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add text inside the hole of the Donut Pie Chart in Flutter

I would like to add centered text in the middle of donut hole pie chart in Flutter like the image below :enter image description here

I am using charts_flutter: ^0.6.0 and this is my code :

new charts.PieChart(
  _project.getExpensesToChartSeries(),
  animate: _animate,
  animationDuration: Duration(milliseconds: 500),
  selectionModels: [
    new charts.SelectionModelConfig(
      type: charts.SelectionModelType.info,
      changedListener: _onSelectionChanged,
    )
  ],
  defaultRenderer: charts.ArcRendererConfig(
    arcWidth: 25,
  ),
)
like image 870
Pyth0nGh057 Avatar asked Nov 28 '25 19:11

Pyth0nGh057


1 Answers

You can use Stack Widget to stack content and get the result you expect, as you see below:

Stack(
    children: <Widget>[
      charts.PieChart(
        _project.getExpensesToChartSeries(),
        animate: true,
        animationDuration: Duration(milliseconds: 500),
        selectionModels: [
          new charts.SelectionModelConfig(
            type: charts.SelectionModelType.info,
            changedListener: _onSelectionChanged,
          )
        ],
        defaultRenderer: charts.ArcRendererConfig(
          arcWidth: 25,
        ),
      ),
      Center(
        child: Text(
          "88%",
          style: TextStyle(
            fontSize: 30.0,
            color: Colors.blue,
            fontWeight: FontWeight.bold
          ),
        ),
      )
    ],
)

enter image description here

like image 126
Luis Miguel Mantilla Avatar answered Dec 01 '25 11:12

Luis Miguel Mantilla