apache / apache/superset

Can't manipulate a categorical x-axis to sort by another variable

Open
#38,249 1 comment 3 reactions 0 assignees View on GitHub
viz:charts:bar
Dominant language
Python
Stars
74.8k
Forks
18.3k
Avg merge
2d 5h
Merged PRs (30d)
685

Description

### Bug description

Backstory:
- Continues #9998 which was closed without completion and #30575 which is a discussion. It's technically a feature request but feels like a bug, to not be able to do such an essential thing in Superset in 2026, so I'm taking the liberty of turning it into an issue,
- The conversation in #34352 sprawled into this broader problem, but it should standalone here. Its PR #37712 might solve part or all of this - it originally was not in scope but I've asked for bar chart custom sorting to be incorporated.

**Users need to be able to sort an x-axis in a custom order by specifying another variable.** See #30575 for examples. Many categorical x-axes have a rigid sorting order that is not alphabetical. For instance:
- Days of the week
- Months of the year
- Group size data (1-5, 6-20, 21-50)

As far as I know, this worked okay when we could use the legacy bar chart, but is a bigger problem now in Superset 6.0.0. Right now users have to create a copy of the x-axis variable and preface it with numbers or varying amounts of whitespace as a sorting order hack. Here I am using `1.Under 18 years` so that it shows up first:

Image

I would rather have a separate variable in my dataset called `age_group_sort_order` and then I could not have the preface numbers cluttering up my chart.

Alternatively, I have used a BI tool that lets a user type the sort order in the dataset UI. This would also be an acceptable way to resolve this problem, IMO. We could even do both: allow sort by another variable AND allow the original variable's sort order to be specified manually.

This applies to any chart with an x-axis: bar chart, line chart, heatmap.

If I'm wrong and there's a way to do this, I am happy to be proven wrong and I will add it to the documentation!

### Screenshots/recordings

_No response_

### Superset version

6.0.0

### Python version

Not applicable

### Node version

Not applicable

### Browser

Not applicable

### Additional context

_No response_

### Checklist

- [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [x] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the examples and discussion in #30575, the history in #9998 and #34352, and the related PR #37712. Compare the sorting behavior needed for bar charts, line charts, and heatmaps, then define whether sorting by another variable, manually specifying order, or both is required; no file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.