Second level axis labels #33209
richardfogaca
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
This seems eminently reasonable to me, but how far does the rabbit hole go? If people add lots of dimensions, to they get lots of x axis layers? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Second level axis labels
Contribution Summary
This contribution introduces an optional secondary axis labels for the ECharts Timeseries chart when configured as a stacked bar chart. When enabled, this secondary axis displays grouping information derived from the metric names, providing an additional layer of context directly on the axis. This is particularly useful when visualizing data with multiple grouping dimensions where the series name contains concatenated dimension values (e.g., "Sales, West", "Sales, East").
How It Works
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx
). This option is stored in the form data asshowSecondaryXAxis
.transformProps.ts
):transformProps
function now checks for theshowSecondaryXAxis
flag.seriesType === 'bar'
andstack
is true), it calls a new functionstackBarXAxisSecondLevel
.transformers.ts
):transformSeries
function now calls a new helpersplitStack
.splitStack
processes thetransformedSeries
object. If stacking is enabled and the series name contains commas (indicating multiple dimensions based on Superset's convention), it splits the name.stack
property of the series (e.g., "West" or "East"). Thisstack
property is ECharts' mechanism for grouping bars visually.stackBarXAxisSecondLevel
intransformers.ts
):echartOptions.xAxis
.stack
values (e.g., "West", "East"). These become the labels for the secondary axis.data
based on thexAxis
column.echartOptions.xAxis
into an array of two axis definitions:offset: offsetReal
) to make space for the second axis. Its labels represent the primary categories (e.g., time periods or categories from the main x-axis dimension).position: 'bottom'
). Itsdata
property is populated with the derivedstack
labels (e.g., "West", "East", "West", "East", ...) repeating for each primary category. This creates the visual grouping effect.echartOptions.legend.data
to use the modified (split) series names for consistency.This prototype currently implements the secondary level for the X-axis. A similar approach could be adopted to implement a secondary Y-axis for horizontally oriented charts by adapting the logic in
stackBarXAxisSecondLevel
(or a new similar function) to modifyechartOptions.yAxis
instead.Screenshots
Fork with working prototype
A prototype with the implementation is available in this fork
Why This Matters
For stacked bar charts representing multiple levels of grouping (often encoded in the metric name), the standard visualization can become cluttered or difficult to interpret subgroup totals. Adding a secondary axis level directly displays these subgroupings (e.g., Regions within a Product Category) below the primary axis categories (e.g., Time Periods). This significantly enhances readability by:
Beta Was this translation helpful? Give feedback.
All reactions