Skip to content

Conversation

@jay-k98
Copy link

@jay-k98 jay-k98 commented Sep 22, 2025

As described in #2003 a "Stacked Pie Chart" was requested. This Pull Request aims to add this feature.

Solution

The Implementation of [StackedPieChart] is very similar to [PieChart]. The biggest difference is drawing a Section with multiple Segments.

The radius of a segment is calculated like this:

SegmentRadius = SectionRadius * SegmentValue / TotalSectionValues

The sweep angles are then calculated like in [PieChart]

Todo's and Improvements

  • Add drawing strokes
  • Extend the Demo (add icon and more examples)
  • Add tests
  • Extract duplicate logic from [PieChart] and [StackedPieChart]

@jay-k98 jay-k98 force-pushed the feature/stacked-pie-chart branch from 378932b to 6a9aec1 Compare September 22, 2025 12:41
@jay-k98 jay-k98 force-pushed the feature/stacked-pie-chart branch 2 times, most recently from d04f72f to 2ecef63 Compare September 30, 2025 08:21
@jay-k98 jay-k98 force-pushed the feature/stacked-pie-chart branch from 2ecef63 to b88f01f Compare October 6, 2025 11:43
@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

❌ Patch coverage is 0% with 479 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.97%. Comparing base (32e75f5) to head (b88f01f).

Files with missing lines Patch % Lines
...t/stacked_pie_chart/stacked_pie_chart_painter.dart 0.00% 262 Missing ⚠️
...hart/stacked_pie_chart/stacked_pie_chart_data.dart 0.00% 111 Missing ⚠️
.../stacked_pie_chart/stacked_pie_chart_renderer.dart 0.00% 74 Missing ⚠️
...src/chart/stacked_pie_chart/stacked_pie_chart.dart 0.00% 20 Missing ⚠️
...rt/stacked_pie_chart/stacked_pie_chart_helper.dart 0.00% 8 Missing ⚠️
lib/src/utils/lerp.dart 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2004       +/-   ##
===========================================
- Coverage   92.49%   81.97%   -10.53%     
===========================================
  Files          50       55        +5     
  Lines        3731     4210      +479     
===========================================
  Hits         3451     3451               
- Misses        280      759      +479     
Flag Coverage Δ
flutter 81.97% <0.00%> (-10.53%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@imaNNeo
Copy link
Owner

imaNNeo commented Oct 26, 2025

Hi, thanks for your contribution.
I think we can use the current implementation of the PieChart to just add the stacked logic into it.
This way, we reuse a lot of code that we already wrote.

Just like what I did for the stacked bar chart here: #112

Please let me know your thoughts on it.

@jay-k98
Copy link
Author

jay-k98 commented Oct 26, 2025

Hi, yeah thank you for responding! I wanted to hear your opinion about that. I'll implement analogous to #112 and add tests :)

@imaNNeo
Copy link
Owner

imaNNeo commented Oct 26, 2025

I appreciate it!
Thanks in advance.

@jay-k98 jay-k98 force-pushed the feature/stacked-pie-chart branch 2 times, most recently from a47be1d to e10651b Compare November 10, 2025 12:50
@jay-k98
Copy link
Author

jay-k98 commented Nov 10, 2025

Hi @imaNNeo i was on vacation but now I'm back and implemented the stacked logic for PieChart. I also updated tests and added a new sample for the example app. Looking forward to your feedback :)

@jay-k98 jay-k98 force-pushed the feature/stacked-pie-chart branch 2 times, most recently from c98c21b to 5bee1b4 Compare November 10, 2025 15:32
@Bazni
Copy link

Bazni commented Dec 17, 2025

Hey 👋,
I think I commented at the wrong place the first time, sorry about that.

Thx for the work. I'm looking to do something like this:
image

Do you think I will be able to do it with your StackedPieChart?

@imaNNeo
Copy link
Owner

imaNNeo commented Dec 20, 2025

Hi @imaNNeo i was on vacation but now I'm back and implemented the stacked logic for PieChart. I also updated tests and added a new sample for the example app. Looking forward to your feedback :)

Can you please update your branch with the latest changes? Then I can check it again.
(You don't need to update the CHANGELOG.md)

Signed-off-by: Jonas Klock <[email protected]>
@jay-k98 jay-k98 force-pushed the feature/stacked-pie-chart branch from 75f60a7 to 271d231 Compare January 5, 2026 12:11
@jay-k98
Copy link
Author

jay-k98 commented Jan 5, 2026

Can you please update your branch with the latest changes? Then I can check it again. (You don't need to update the CHANGELOG.md)

Hey, I updated the branch and removed CHANGELOG.md changes.

@jay-k98
Copy link
Author

jay-k98 commented Jan 5, 2026

Hey 👋, I think I commented at the wrong place the first time, sorry about that.

Thx for the work. I'm looking to do something like this: image

Do you think I will be able to do it with your StackedPieChart?

Yes, the green and red part will definetly be possible. You can checkout the branch of this PR and run the example. Pie Chart Sample 4 is pretty close to the screenshot you provided.

About the grid you might need to get creative.. :D But I guess you could put two PieCharts in a Stack and use the "lower" PieChart to create the grid with section and segment outlines as well as labels. Hope this helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants