PieChart: Fix sorting for null values in piechart (#39516) (#39556)

* Fix sorting for null values in piechart

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
(cherry picked from commit 4a6e354497)

Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2021-09-23 11:10:24 +02:00
committed by GitHub
co-authored by Oscar Kilhed
parent 1b8255e317
commit ef7a2bda39
@@ -90,7 +90,15 @@ function getLegend(props: Props, displayValues: FieldDisplay[]) {
const legendItems = displayValues
// Since the pie chart is always sorted, let's sort the legend as well.
.sort((a, b) => b.display.numeric - a.display.numeric)
.sort((a, b) => {
if (isNaN(a.display.numeric)) {
return 1;
} else if (isNaN(b.display.numeric)) {
return -1;
} else {
return b.display.numeric - a.display.numeric;
}
})
.map<VizLegendItem>((value, idx) => {
const hidden = value.field.custom.hideFrom.viz;
const display = value.display;