fl_chart icon indicating copy to clipboard operation
fl_chart copied to clipboard

Feature: Add StackedPieChart

Open jay-k98 opened this issue 3 months ago • 5 comments

As described in https://github.com/imaNNeo/fl_chart/issues/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 avatar Sep 22 '25 12:09 jay-k98

Codecov Report

:x: Patch coverage is 0% with 479 lines in your changes missing coverage. Please review. :white_check_mark: 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 :warning:
...hart/stacked_pie_chart/stacked_pie_chart_data.dart 0.00% 111 Missing :warning:
.../stacked_pie_chart/stacked_pie_chart_renderer.dart 0.00% 74 Missing :warning:
...src/chart/stacked_pie_chart/stacked_pie_chart.dart 0.00% 20 Missing :warning:
...rt/stacked_pie_chart/stacked_pie_chart_helper.dart 0.00% 8 Missing :warning:
lib/src/utils/lerp.dart 0.00% 4 Missing :warning:
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%) :arrow_down:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Oct 26 '25 19:10 codecov[bot]

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.

imaNNeo avatar Oct 26 '25 19:10 imaNNeo

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

jay-k98 avatar Oct 26 '25 19:10 jay-k98

I appreciate it! Thanks in advance.

imaNNeo avatar Oct 26 '25 19:10 imaNNeo

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 avatar Nov 10 '25 12:11 jay-k98

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?

Bazni avatar Dec 17 '25 04:12 Bazni