-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mixed time-series; time-series bar chart v2] D3 format of saved metric is ignored; bar values ignore D3 format of the chart #18234
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue |
I managed to come up with a quick fix for this issue, which works for my own charts: 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>`);
|
Closing this as stale since it's been silent for so long, and we're trying to steer toward a more actionable Issues backlog. If people are still encountering this in current versions (currently 3.x) please open a new Issue or a PR to address the problem. |
I can replicate this on both, mixed time-series and time-series bar chart v2.
The D3 format of a saved metric is not respected in the
How to reproduce the bug
Expected results
The y-axis labels, the tooltips and the bar values are formatted according to the defined D3 format of the metric.
Actual results
The d3 format of the metric is entirely ignored.
When overriding the y-axis format via the chart's Customize settings, the y-labels and tooltips are respecting this override.
The bar values need some differentiation here, though:
Screenshots
Environment
Checklist
Make sure to follow these steps before submitting your issue - thank you!
The text was updated successfully, but these errors were encountered: