dosubot[bot] commented on issue #30238:
URL: https://github.com/apache/superset/issues/30238#issuecomment-2343499888

   <!-- Greeting -->
   @HJelinkova Hello there! 👋 I'm here to help you with any bugs, questions, or 
contributions you have for the project.
   
   <!-- Answer -->
   I found some similar discussions and a closed issue related to the sorting 
functionality in bar charts:
   
   1. [How to fix the sorting of bars in bar-chart by 
metric?](https://github.com/apache/superset/discussions/28636) (unsolved) 
<sup>[[1]](https://github.com/apache/superset/discussions/28636)</sup>.
   2. [Sorting in New Bar 
Chart](https://github.com/apache/superset/discussions/25250) (unsolved) 
<sup>[[2]](https://github.com/apache/superset/discussions/25250)</sup>.
   3. [With GENERIC_CHART_AXES enabled, SORT BY doesn't seem to 
work](https://github.com/apache/superset/issues/20198) (closed) 
<sup>[[3]](https://github.com/apache/superset/issues/20198)</sup>.
   
   The closed issue suggests that the 'SORT BY' option is intended for sorting 
the series when using series limit, not for custom sorting of X-axis labels 
with GENERIC_CHART_AXES. Custom sorting of X-axis labels is not supported yet, 
and you should request that feature.
   
   To address the issue in Superset version 4.0.2, ensure that the 
`sortOperator` is correctly configured and that the `formData` includes the 
necessary sorting parameters. Here is the relevant part of the code that 
handles the sorting logic:
   
   ```ts
   if (
     isDefined(formData?.x_axis_sort) &&
     isDefined(formData?.x_axis_sort_asc) &&
     sortableLabels.includes(formData.x_axis_sort) &&
     // the sort operator doesn't support sort-by multiple series.
     isEmpty(formData.groupby)
   ) {
     if (formData.x_axis_sort === getXAxisLabel(formData)) {
       return {
         operation: 'sort',
         options: {
           is_sort_index: true,
           ascending: formData.x_axis_sort_asc,
         },
       };
     }
     return {
       operation: 'sort',
       options: {
         by: formData.x_axis_sort,
         ascending: formData.x_axis_sort_asc,
       },
     };
   }
   ```
   
   Ensure that:
   1. `formData.x_axis_sort` is set to the label you want to sort by.
   2. `formData.x_axis_sort_asc` is set to `true` for ascending order or 
`false` for descending order.
   3. `formData.groupby` is empty, as the sort operator does not support 
sorting by multiple series 
<sup>[[4]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-chart-controls/src/operators/sortOperator.ts)</sup>.
   
   Additionally, the following controls in the Superset configuration files are 
relevant for sorting functionality:
   - `xAxisSortControl`
   - `xAxisSortAscControl`
   - `xAxisForceCategoricalControl`
   - `xAxisSortSeriesControl`
   - `xAxisSortSeriesAscendingControl` 
<sup>[[5]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/customControls.tsx)</sup>.
   
   These controls ensure that the sorting functionality is applied correctly 
when `x_axis_sort` and `x_axis_sort_asc` are defined and valid.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


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