PieChart: Add panel options for ascending/descending sort, and no sorting (#109564)

* Add PieSortOption.

* Add sorting options to pie chart panel options.

* Fix that sorting is not part of the panel options.

* Implement custom sorting in piechart and piechart legend.

* Update piechart documentation

* Fix default and clockwise/counterclockwise confusion.

* refactor(piechart): use asc/desc terminology instead of clockwise

* fix(piechart): simplify comparator sort, avoid a/b swap mutation

* fix(pichart): remove redundant sorting from Pie component invocation

* refactor(piechart): hoist comparator for sorting display values

* docs(piechart): include recommendations from @imatwawanaimatwawana

* test(piechart): add test coverage for new sorting comparator

* chore(piechart): regenerate Cue schema files

* docs(piechart): apply suggestions from @imatwawana code review

Co-authored-by: Isabel Matwawana <76437239+imatwawana@users.noreply.github.com>

* fix(piechart): fix typo, match punctuation in option description

* chore(piechart): update schema to use existing `common.SortOrder` instead of custom

Co-authored-by: Paul Marbach <paul.marbach@grafana.com>

---------

Co-authored-by: Lukas Wieg <lukaswieg@googlemail.com>
Co-authored-by: Isabel Matwawana <76437239+imatwawana@users.noreply.github.com>
Co-authored-by: Paul Marbach <paul.marbach@grafana.com>
This commit is contained in:
Jesse David Peterson
2025-08-14 16:46:53 -04:00
committed by GitHub
co-authored by Isabel Matwawana Paul Marbach Lukas Wieg
parent 17444fdc0d
commit cc651e2e6e
8 changed files with 104 additions and 14 deletions
@@ -136,6 +136,15 @@ Select the pie chart display style. Choose from **Pie** or **Donut**.
![Pie chart types](/media/docs/grafana/panels-visualizations/screenshot-pie-chart-types.png)
#### Slice sorting
By default, the pie chart is sorted so that the slices decrease in size clockwise around the circle.
You can configure the sorting of the slices, and by extension the legend, with the following options:
- **Descending** - The slices decrease in size, clockwise (default).
- **Ascending** - The slices increase in size, clockwise.
- **None** - No sorting is applied. The original order of the data is maintained.
#### Labels
Select labels to display on the pie chart. You can select more than one.