Bug description
When creating a bar chart there is the option to sort the x-axis or y-axis when in horizontal mode. This dropdown option presents different values when a dimension is defined in the section "DIMENSIONS" compared to when there is no dimension defined. In our case we want to order the x-axis by another column in our dataset, so we fill the "SORT BY" section as follows:
then we get the following options to sort the x-axis, which work well and allow us to order the x-axis by that dataset column:
however, when we define a dimension to present our metric stacked by that dimension the options to sort the x-axis change to this:
This way we are not able to order the x-axis by the order column in our dataset.
Thank you for your time in advance.
NOTE: Using the chart "Bar Chart (legacy)" we can achieve the intended x-axis ordering with the following configuration:
Screenshots/recordings
No response
Superset version
4.1.3
Python version
3.9
Node version
16
Browser
Chrome
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.
Comment From: dosubot[bot]
The difference in "X-AXIS SORT BY" options when a dimension is set in bar charts is intentional and comes from how the frontend control logic is implemented. When no dimension is set, you can sort by any column or metric in your dataset. But as soon as you add a dimension (i.e., use "DIMENSIONS" to group or stack), the sort options are restricted to a fixed set: category name, total value, minimum value, maximum value, and average value. This is hardcoded in the frontend and not a backend limitation or bug—it's how the control is designed to work in Superset 4.1.3 [source].
There isn't a built-in workaround to sort by an arbitrary dataset column when a dimension is set. If you need to sort by a specific column, you might consider pre-sorting your data in the dataset or creating a calculated column that encodes your desired order, then use "Category name" sorting. Otherwise, this limitation would require a feature enhancement in Superset.
If you want to review or customize this behavior, the relevant logic is in the frontend code, specifically in the xAxisSortControl
and the SORT_SERIES_CHOICES
constant [source].
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other