Saturday, April 23, 2022

[FIXED] How can we draw pie chart with different radius in flutter?

Issue

In flutter, I am trying to implement a pie chart with different radius in each slice as shown in figure below? I searched and tried different plugins in pub.dev, but didn't find any plugin with my requirements. How can I do this in flutter? Thank you.

enter image description here


Solution

The lib fl_chart can help you.

https://pub.dev/packages/fl_chart

The use is very simple, you can pass the radius value in PieChartSectionData, which can be the same of the value or you can configure for other purpose:

PieChart(
PieChartData(centerSpaceRadius: 30, sections: [
PieChartSectionData(
    color: const Color(0xff0293ee),
    value: 40,
    title: '40%',
    radius: 40,
    titleStyle: TextStyle(
        fontSize: 12,
        fontWeight: FontWeight.bold,
        color: const Color(0xffffffff)),
),
PieChartSectionData(
    color: const Color(0xfff8b250),
    value: 30,
    title: '30%',
    radius: 30,
    titleStyle: TextStyle(
        fontSize: 14,
        fontWeight: FontWeight.bold,
        color: const Color(0xffffffff)),
)
]))

Pie Chart with different radius values result:

Pie Chart with different radius values



Answered By - Murilo Erhardt
Answer Checked By - Cary Denson (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.