redash
redash copied to clipboard
Pie Chart - Sort Legend by Label
Redash 2.0.0+b2990
I'm trying to do a pie chart to count the number of people by age bands (<50, 60-70, 80-90, 90+).
I'd like the legend items to be displayed in alphabetical order but at the moment they're ordered based on quantity in descending order. I can't see an existing way to change this.
This looks to be related to #1354 but there they are concerned with a consistent colour rather than a consistent ordering.
I'm looking into this too. I think a solution to your problem would also solve the issue in #1354.
I believe the solution lies in first collecting an array of unique legend items prior to colour assignment. These unique values would be used in name:value paring with colours prior to plotting, with colours assigned in accordance with the name:value pairs. I think this could be achieved by altering ./client/app/visualizations/chart/plotly.js
I'm fairly new to redash, so I'm not sure if this would clash with any filtering etc?
Thoughts?
Actually, the key is disable automatic y-value sort by setting
const plotlySeries = { sort: false }
when globalSeriesType is 'pie'.
I think this feature should sync with "Sort Values" of X Axis option. The thing is, that "Sort Values" of X Axis option is ON by default, so adding the above feature will automatically alter the way most of existing Pie charts look.
Thoughts on how to handle backward compatibility?
I've suddenly discovered that there is now no "X-axis" and "Y-axis" tabs in Pie Chart options at all. I've checked latest digests and release docs and didn't find anything about that. Is this a bug or these options are disabled on purpose?
All available option tabs now:
no X/Y axis tabs presented.
Thanks.
Hi @funkindy! These tabs were removed on purpose because X/Y axis settings are not applicable to Pie charts.
Hi, @kravets-levko! Thanks for the quick response. I agree that there is not much what we can customize on Pie Chart axes. But, returning to the issue topic, is there a way to sort legend on pie chart with labels (not values) without changing front-end code now? Thanks a lot.
I'd also be interested in a feature that allowed users to sort a legend alphabetically, if possible!
Just a ping here since the issue has been open for 7 years with no activity. Sort pie legend by label name, not by value or % - Is it possible to implement?