openaphid commented on issue #18234:
URL: https://github.com/apache/superset/issues/18234#issuecomment-1170870692

   I managed to come up with a quick fix for this issue, which works for my own 
charts:
   
   ```patch
   diff --git 
a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
 
b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
   index 5b3b5523e..41e7fa356 100644
   --- 
a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
   +++ 
b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
   @@ -95,7 +95,7 @@ export default function transformProps(
        theme,
        annotationData = {},
      } = chartProps;
   -  const { verboseMap = {} } = datasource;
   +  const { verboseMap = {}, columnFormats } = datasource;
      const [queryData] = queriesData;
      const { data = [] } = queryData as TimeseriesChartDataResponseResult;
      const dataTypes = getColtypesMapping(queryData);
   @@ -140,6 +140,7 @@ export default function transformProps(
        sliceId,
        timeGrainSqla,
        orientation,
   +    metrics,
      }: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
    
      const colorScale = CategoricalColorNamespace.getScale(colorScheme as 
string);
   @@ -173,9 +174,34 @@ export default function transformProps(
      const xAxisDataType = dataTypes?.[xAxisCol];
      const xAxisType = getAxisType(xAxisDataType);
      const series: SeriesOption[] = [];
   -  const formatter = getNumberFormatter(
   -    contributionMode || isAreaExpand ? ',.0%' : yAxisFormat,
   -  );
   +
   +  // fix https://github.com/apache/superset/issues/18234
   +  const funcFindFormatter = (seriesName) => {
   +    let bestFormat = yAxisFormat
   +    if (bestFormat === 'SMART_NUMBER') { // if it's not specified in chart 
options
   +      if (metrics.length === 1) { // only one metric, seriesName is not 
prefixed with metric name
   +        const format = columnFormats[metrics[0] || ""]
   +        if (format)
   +          bestFormat = format
   +      } else if (seriesName) { // the chart has multiple metrics, the 
format can be extracted from prefix
   +        for (let m of metrics) {
   +          if (seriesName.startsWith(m + ',')) {
   +            const format = columnFormats[m]
   +            if (format) {
   +              bestFormat = format
   +            }
   +            break
   +          }
   +        }
   +      }
   +    } 
   +
   +    const formatter = getNumberFormatter(
   +      contributionMode || isAreaExpand ? ',.0%' : bestFormat,
   +    );  
   +
   +    return formatter
   +  }
    
      rawSeries.forEach(entry => {
        const lineStyle = isDerivedSeries(entry, chartProps.rawFormData)
   @@ -190,7 +216,7 @@ export default function transformProps(
          areaOpacity: opacity,
          seriesType,
          stack,
   -      formatter,
   +      formatter: funcFindFormatter(entry.id),
          showValue,
          onlyTotal,
          totalStackedValues,
   @@ -337,7 +363,7 @@ export default function transformProps(
        max,
        minorTick: { show: true },
        minorSplitLine: { show: minorSplitLine },
   -    axisLabel: { formatter },
   +    axisLabel: { formatter: funcFindFormatter('') }, 
        scale: truncateYAxis,
        name: yAxisTitle,
        nameGap: convertInteger(yAxisTitleMargin),
   @@ -380,7 +406,7 @@ export default function transformProps(
              const content = formatForecastTooltipSeries({
                ...value,
                seriesName: key,
   -            formatter,
   +            formatter: funcFindFormatter(key),
              });
              if (currentSeries.name === key) {
                rows.push(`<span style="font-weight: 700">${content}</span>`);
   
   ```


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