GitHub user LoneWolfRakesh created a discussion: ECharts Bar Chart: Cannot sort descending by total metric when applying a Dimension (Sorts Alphabetically instead)
**Superset Version:** [6.0.0] **The Goal:** I am trying to create a horizontal Bar Chart that shows a list of products, color-coded by their "Product Type". I need the chart to sort strictly descending from the highest total score to the lowest. **The Mock Data:** Imagine a simple dataset of products. A product only belongs to ONE type (Sparse Data). * Product A | Type 1 | Score: 85 * Product B | Type 1 | Score: 60 * Product C | Type 2 | Score: 90 * Product D | Type 2 | Score: 40 **Chart Configuration:** * **Y-axis:** `Product_Name` * **Metrics:** `AVG(Score)` * **Dimensions:** `Type` *(This successfully splits the bars into two colors)* * **Sort Query By:** `AVG(Score)` (Descending) * **Customize Tab:** Stacked Style = `Stack`, Sort Series By = `Total value` **The Problem:** When the `Type` dimension is empty, the chart perfectly sorts by the highest score (C, A, B, D). However, the moment I drop `Type` into the Dimensions box to get my colors, Superset pivots the data. Because ECharts encounters `NULL` values (e.g., Product A has no score for Type 2), it discards the mathematical sort entirely and defaults to sorting the Y-axis **alphabetically** (A, B, C, D). **EXPECTED BEHAVIOR (Sorted by Total Size):** Product C | ██████████████████ (Category 2) Product A | ██████████████ (Category 1) Product B | ██████████ (Category 1) Product D | ██████ (Category 2) **ACTUAL BUG BEHAVIOR (Sorted Alphabetically):** Product A | ██████████████ Product B | ██████████ Product C | ██████████████████ Product D | ██████ **What I have already tried (that didn't work):** 1. **Custom SQL Zero-Filling:** I tried forcing `COALESCE(AVG(Score), 0)` to prevent the sparse data panic, but ECharts still overrides the sort. 2. **Hidden Sort Metrics:** I tried adding a fractional invisible metric `(AVG(Score) * 0.00001)` and setting the master sort to that, but the frontend still ignores it. 3. **Dual Metrics instead of Dimensions:** I removed the Dimension entirely and created two separate metrics `AVG(CASE WHEN Type='1'...)`. This still resulted in alphabetical sorting. Has anyone found a reliable frontend workaround or Custom CSS/JSON trick to force ECharts to respect the `Total value` descending sort when dealing with a split dimension? Any guidance would be massively appreciated! GitHub link: https://github.com/apache/superset/discussions/38245 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
