venkatamandavilli-code commented on issue #35853:
URL: https://github.com/apache/superset/issues/35853#issuecomment-4156971051
Here is my Proposed Fix
The root of the problem is that Superset treats string values on the x‑axis
as *categorical labels*, not as ordered numbers. So even if the strings look
like `"202408"`, Superset doesn’t treat them as a sequence — it just treats
them as labels. That’s why the line jumps over `"202408"` even though it exists.
To fix this, we just need to detect when a string is actually a number in
disguise (like `"202401"`, `"202402"`, etc.) and convert it into a real number
before sending it to the chart.
Once the values become numbers, the chart uses a continuous axis, and the
line connects all points correctly.
Frontend Fix (JavaScript)
Before building the chart, check if all x‑axis values are numeric strings.
If they are, convert them to numbers and use a continuous axis.
```js
function isNumericString(value) {
return typeof value === 'string' && /^[0-9]+$/.test(value);
}
const allNumericStrings = data.every(row => isNumericString(row[xAxisKey]));
if (allNumericStrings) {
// Treat as numbers so the line chart behaves correctly
xAxis.type = 'value';
data.forEach(row => {
row[xAxisKey] = Number(row[xAxisKey]);
});
} else {
xAxis.type = 'category';
}
```
What this does:
If the x‑axis values look like `"202408"`, they get converted to `202408`,
and the chart behaves normally.
Backend Fix (Python)
We can also normalize the data earlier, right after the query runs.
```python
def normalize_numeric_strings(df, dimension):
if df[dimension].dtype == "object":
if df[dimension].str.match(r"^\d+$").all():
df[dimension] = df[dimension].astype(int)
return df
```
Apply this during post‑processing so the frontend always gets clean numeric
values.
Why This Fix Works
- Line charts behave correctly when the x‑axis is numeric
- Numeric‑looking strings (like `"202408"`) are treated as numbers
- No categories get skipped
- Behavior matches how Superset v4 used to work
- Dashboards using YYYYMM or similar formats start working again
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]