redash icon indicating copy to clipboard operation
redash copied to clipboard

Pie Chart - Sort Legend by Label

Open George-D-S opened this issue 7 years ago • 7 comments

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.

George-D-S avatar Oct 11 '17 15:10 George-D-S

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?

wa721 avatar Oct 16 '17 16:10 wa721

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?

deecay avatar Oct 17 '17 08:10 deecay

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: image

no X/Y axis tabs presented.

Thanks.

funkindy avatar Feb 11 '20 08:02 funkindy

Hi @funkindy! These tabs were removed on purpose because X/Y axis settings are not applicable to Pie charts.

kravets-levko avatar Feb 11 '20 09:02 kravets-levko

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.

funkindy avatar Feb 11 '20 09:02 funkindy

I'd also be interested in a feature that allowed users to sort a legend alphabetically, if possible!

Veganveins avatar Nov 01 '21 18:11 Veganveins

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?

dbabits avatar Feb 07 '24 20:02 dbabits