How to customize the order of bars in a Superset Chart
Asked Answered
R

2

6

In Apache Superset I want to create a Bar Chart - just like the 'Vaccine Candidates per Phase' from the 'COVID Vaccine Dashboard'.

Goal: We want to customize the order of the bars without adding '0', '1' to the labels to then order it alphabetically, as it was done in this graph.

Vaccine Candidates per Phase

Here it seems the order of the bars is according to the 'count' variable.

How can we customize the order of the bars? How can we specify in which order they should appear (without relying on alphabetical ordering)?

Romeo answered 8/8, 2022 at 14:55 Comment(0)
S
8

I would love to be wrong, but I believe this is a missing feature currently (as of Superset 2.0.0). I've been unable to get that sorting working with the Bar Chart v2 Chart Type.

Here's a GitHub issue for this same problem and a reply from a top Superset contributor saying that actually, it would be a feature request, not a bug report. Here's a feature request for implementing this behavior on the Bar Chart v2 chart type if you want to upvote or comment.

I'm newer to Superset but from what I can tell, sorting order control worked on the older bar chart types. For instance, it looks like this was closed as implemented on the Time Series Bar Chart type. But it's not yet implemented for the newest EChart-powered Bar Chart v2.

For what it's worth, I've also been unable to control the order of stacked bars on a Mixed Chart - I suspect it's the same root cause.

Supper answered 15/8, 2022 at 1:45 Comment(0)
R
6

I found a workaround: Instead of pasting numbers to the name, we can paste empty spaces. The more leading empty spaces, the further on the left of the axis the label is. Plus, we do not see the empty spaces in the name, as such:

case 
when clinical_stage = 'Pre-clinical' then
CONCAT('     ', clinical_stage)
when clinical_stage = 'Phase I' then
CONCAT('    ', clinical_stage)
when clinical_stage = 'Phase II' then 
CONCAT('   ', clinical_stage)
when clinical_stage = 'Phase III' then 
CONCAT('  ', clinical_stage)
when clinical_stage = 'Phase IV' then
CONCAT(' ', clinical_stage) 
end
Romeo answered 16/12, 2022 at 16:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.