FrancescoCastaldi commented on issue #45888:
URL: https://github.com/apache/superset/issues/45888#issuecomment-6524010860

   ### Root Cause Analysis & Solution
   
   In 
`superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberWithTrendline/transformProps.ts`,
 sorting is performed as `(b[0] - a[0])`.
   
   When timestamps are returned from the database as string representations 
(such as ISO datetime strings from ClickHouse or certain SQL dialects), string 
subtraction evaluates to `NaN`. Because JavaScript `.sort()` preserves relative 
order when the comparator returns `NaN`, the array remains in whatever order 
the database returned the rows. Consequently, `sortedData[0]` picks the first 
row returned by the query rather than the latest chronological data point.
   
   #### Solution
   1. In `transformProps.ts`, convert the x-axis value to a numeric timestamp 
using `new Date(val).getTime()` (or `Date.parse`) before computing differences 
in `.sort()`.
   2. In `buildQuery.ts`, explicitly set `orderby: [[timeColumn, true]]` to 
ensure the SQL query returns rows in ascending chronological order from the 
database.
   
   This fix is verified with unit tests covering out-of-order ISO datetime 
strings and has been committed to branch `fix/community-unanswered-issues` 
(commit `d7d1efc77e0`) at 
https://github.com/FrancescoCastaldi/superset/tree/fix/community-unanswered-issues.
   


-- 
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]

Reply via email to