Skip to content

[charts] Add data-series to bar charts#18413

Merged
bernardobelchior merged 9 commits intomui:masterfrom
bernardobelchior:bar-charts-data-series
Jun 23, 2025
Merged

[charts] Add data-series to bar charts#18413
bernardobelchior merged 9 commits intomui:masterfrom
bernardobelchior:bar-charts-data-series

Conversation

@bernardobelchior
Copy link
Copy Markdown
Member

Part of #18047.

image

@bernardobelchior
Copy link
Copy Markdown
Member Author

A bit unsure if I should add a group around each series' bars, similar to the scatter chart. That way we wouldn't need one data-series per bar. What do you think?

@bernardobelchior bernardobelchior added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: charts Changes related to the charts. labels Jun 17, 2025
@mui-bot
Copy link
Copy Markdown

mui-bot commented Jun 17, 2025

Deploy preview: https://deploy-preview-18413--material-ui-x.netlify.app/

Updated pages:

Bundle size report

Total Size Change: 🔺+1.71KB(+0.01%) - Total Gzip Change: 🔺+359B(+0.01%)
Files: 122 total (0 added, 0 removed, 26 changed)

Show details for 100 more bundles (22 more not shown)

@mui/x-chartsparsed: 🔺+440B(+0.16%) gzip: 🔺+114B(+0.14%)
@mui/x-charts-proparsed: 🔺+440B(+0.13%) gzip: 🔺+117B(+0.11%)
@mui/x-charts/BarChartparsed: 🔺+437B(+0.25%) gzip: 🔺+107B(+0.19%)
@mui/x-charts/SparkLineChartparsed: 🔺+427B(+0.24%) gzip: 🔺+118B(+0.21%)
@mui/x-charts-pro/BarChartProparsed: 🔺+390B(+0.18%) gzip: 🔺+83B(+0.12%)
@mui/x-charts-pro/FunnelChartparsed: ▼-39B(-0.02%) gzip: ▼-17B(-0.03%)
@mui/x-charts-pro/Heatmapparsed: ▼-39B(-0.02%) gzip: ▼-17B(-0.03%)
@mui/x-charts-pro/LineChartProparsed: ▼-39B(-0.02%) gzip: ▼-16B(-0.02%)
@mui/x-charts-pro/PieChartProparsed: ▼-39B(-0.02%) gzip: ▼-24B(-0.04%)
@mui/x-charts-pro/RadarChartProparsed: ▼-39B(-0.02%) gzip: ▼-15B(-0.03%)
@mui/x-charts-pro/ScatterChartProparsed: ▼-39B(-0.02%) gzip: ▼-15B(-0.02%)
@mui/x-charts/ChartsLegendparsed: ▼-39B(-0.05%) gzip: ▼-16B(-0.06%)
@mui/x-charts/LineChartparsed: ▼-39B(-0.02%) gzip: ▼-15B(-0.02%)
@mui/x-charts/PieChartparsed: ▼-39B(-0.02%) gzip: ▼-16B(-0.03%)
@mui/x-charts/RadarChartparsed: ▼-39B(-0.02%) gzip: ▼-18B(-0.03%)
@mui/x-charts/ScatterChartparsed: ▼-39B(-0.02%) gzip: ▼-20B(-0.04%)
@mui/x-charts-pro/ChartContainerProparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts-pro/ChartDataProviderProparsed: 0B(0.00%) gzip: 🔺+1B(0.00%)
@mui/x-charts-pro/ChartsToolbarProparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts-pro/ChartZoomSliderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartContainerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartDataProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsAxisparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsAxisHighlightparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsClipPathparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsGridparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsLabelparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsLocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsOverlayparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsReferenceLineparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsSurfaceparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsTextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsTooltipparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsXAxisparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsYAxisparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/Gaugeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/Toolbarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-gridparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-grid-premiumparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-grid-premium/DataGridPremiumparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-grid-proparsed: 0B(0.00%) gzip: 🔺+1B(0.00%)
@mui/x-data-grid-pro/DataGridProparsed: 0B(0.00%) gzip: 🔺+1B(0.00%)
@mui/x-data-grid/DataGridparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickersparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-proparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterDateFnsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterDateFnsJalaliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterDayjsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterLuxonparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterMomentparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterMomentHijriparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterMomentJalaaliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DateRangeCalendarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DateRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DateRangePickerDayparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DateRangePickerDay2parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DateTimeRangePickerparsed: 0B(0.00%) gzip: 🔺+1B(0.00%)
@mui/x-date-pickers-pro/DesktopDateRangePickerparsed: 0B(0.00%) gzip: 🔺+1B(0.00%)
@mui/x-date-pickers-pro/DesktopDateTimeRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DesktopTimeRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/LocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/MobileDateRangePickerparsed: 0B(0.00%) gzip: ▼-1B(0.00%)
@mui/x-date-pickers-pro/MobileDateTimeRangePickerparsed: 0B(0.00%) gzip: 🔺+2B(0.00%)
@mui/x-date-pickers-pro/MobileTimeRangePickerparsed: 0B(0.00%) gzip: 🔺+1B(0.00%)
@mui/x-date-pickers-pro/MultiInputDateRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/MultiInputDateTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/MultiInputTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/PickersRangeCalendarHeaderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/SingleInputDateRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/SingleInputDateTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/SingleInputTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/StaticDateRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/TimeRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterDateFnsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterDateFnsBaseparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterDateFnsJalaliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterDayjsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterLuxonparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterMomentparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterMomentHijriparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterMomentJalaaliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DateCalendarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DateFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DatePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DateTimeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DayCalendarSkeletonparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DesktopDatePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DesktopDateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DesktopTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DigitalClockparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/LocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MobileDatePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MobileDateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MobileTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MonthCalendarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MultiSectionDigitalClockparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/PickerDay2parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/PickersActionBarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/PickersCalendarHeaderparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against e0fbc9e

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 17, 2025

CodSpeed Performance Report

Merging #18413 will not alter performance

Comparing bernardobelchior:bar-charts-data-series (e0fbc9e) with master (2e1ad0d)

Summary

✅ 9 untouched benchmarks

Comment thread packages/x-charts/src/BarChart/barElementClasses.ts Outdated
@bernardobelchior bernardobelchior force-pushed the bar-charts-data-series branch from 18c096d to 9bc7286 Compare June 17, 2025 16:53
@bernardobelchior bernardobelchior marked this pull request as ready for review June 17, 2025 16:53
@JCQuintas
Copy link
Copy Markdown
Member

A bit unsure if I should add a group around each series' bars, similar to the scatter chart. That way we wouldn't need one data-series per bar. What do you think?

Yeah, right now is a bit tricky, because charts behave and are built differently, with the funnel I had to have a <g> wrap all the sections/labels for a series

#18067

@alexfauquette
Copy link
Copy Markdown
Member

alexfauquette commented Jun 18, 2025

A bit unsure if I should add a group around each series' bars, similar to the scatter chart. That way we wouldn't need one data-series per bar. What do you think?

That will require some update in the data processing, but nothing too drastic. I would be infoavor of testing it. And if no performance draw back, let's go.

-    return groupIds.flatMap((seriesId) => {
+    return groupIds.map((seriesId) => {

If it does not deteriorate performances, why not.

The PR does not seems to impact the BarLabelPlot which also renders element related to the series.

Also is their a reason to don't add the data-highlighted?

@bernardobelchior
Copy link
Copy Markdown
Member Author

The PR does not seems to impact the BarLabelPlot which also renders element related to the series.

What do you mean? Are you saying that we should also add data-series, data-highlighted and data-faded to BarLabelPlot? I wasn't sure if I should and was planning on waiting to hear use cases first, but I can do it now if you think it's worth it.

Also is their a reason to don't add the data-highlighted?

No, just forgot. Added it in the most recent commit

@alexfauquette
Copy link
Copy Markdown
Member

I wasn't sure if I should and was planning on waiting to hear use cases first, but I can do it now if you think it's worth it.

For me it's a nice to have, because the component structure is dependent of the expected visual render. In bar chart we do

<Bars seriesId=A />
<Bars seriesId=B />
<Labels seriesId=A />
<Labels seriesId=B />

and not

<Bars seriesId=A />
<Labels seriesId=A />
<Bars seriesId=B />
<Labels seriesId=B />

because we want labels to be on top of all rectangles

Thand to the mix of data-att and CSS classes we will enable a clear devExp:

  • data-attr for series and state.

  • classes for element type

  • [data-series="A"]

  • .barElement-root[data-series="A"]

  • .barLabel-root[data-series="A"]

@bernardobelchior
Copy link
Copy Markdown
Member Author

I wasn't sure if I should and was planning on waiting to hear use cases first, but I can do it now if you think it's worth it.

For me it's a nice to have, because the component structure is dependent of the expected visual render. In bar chart we do

<Bars seriesId=A />
<Bars seriesId=B />
<Labels seriesId=A />
<Labels seriesId=B />

and not

<Bars seriesId=A />
<Labels seriesId=A />
<Bars seriesId=B />
<Labels seriesId=B />

because we want labels to be on top of all rectangles

Thand to the mix of data-att and CSS classes we will enable a clear devExp:

  • data-attr for series and state.
  • classes for element type
  • [data-series="A"]
  • .barElement-root[data-series="A"]
  • .barLabel-root[data-series="A"]

Added the series ID to the bar label plot as well 👍

Comment thread docs/data/charts/bars/BarGradient.tsx Outdated
Comment on lines +12 to +14
{ id: 1, data: [4, 3, 5] },
{ id: 2, data: [1, 6, 3] },
{ id: 3, data: [2, 5, 6] },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If in v9 we want to move to string we should not demonstrate number in the docs.

Suggested change
{ id: 1, data: [4, 3, 5] },
{ id: 2, data: [1, 6, 3] },
{ id: 3, data: [2, 5, 6] },
{ id: 'id-1', data: [4, 3, 5] },
{ id: 'id-2', data: [1, 6, 3] },
{ id: 'id-3', data: [2, 5, 6] },

Can be done in a follow up with other demos doing the same stuff

Comment thread docs/data/charts/bars/bars.md Outdated

You can customize the bar chart elements using CSS selectors.

Each series renders a `g` element that contains a `data-series` attribute. You can use this attribute to target elements based on their series.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Each series renders a `g` element that contains a `data-series` attribute. You can use this attribute to target elements based on their series.
Each series renders a `g` element that contains a `data-series` attribute.
You can use this attribute to target elements based on their series.

Comment on lines +21 to +23
'root',
'series',
'seriesLabels',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to share some thaught.

I was considering to propose the following. But it does not work well with classes generation

  • barClasses.root: removed
  • barClasses.series: barLabelClasses.seriesGroup
  • barClasses.seriesLabels: barLabelClasses.seriesGroup

I've open an issue for v9 on this topic #18496

@bernardobelchior bernardobelchior enabled auto-merge (squash) June 23, 2025 11:27
@bernardobelchior bernardobelchior merged commit 525415c into mui:master Jun 23, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: charts Changes related to the charts. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants