[charts] Add demo for displaying the sum of all values from the stacked series on top of the stacked bars#22879
Conversation
…ed series on top of the stacked bars
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
There was a problem hiding this comment.
Pull request overview
Adds a new bar-charts documentation demo showing how to render “stack total” labels above stacked bars by composing a custom overlay component inside ChartsContainer.
Changes:
- Added a new
StackTotalLabelsdemo that computes totals viauseBarSeries()and positions labels usinguseXScale()/useYScale(). - Documented the approach in the Bars docs under a new “Stack total labels” section.
- Added both TSX source and generated JS demo files.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| docs/data/charts/bars/StackTotalLabels.tsx | New TypeScript demo overlay that computes and renders stack total labels. |
| docs/data/charts/bars/StackTotalLabels.js | Generated JavaScript version of the same demo. |
| docs/data/charts/bars/bars.md | Adds a new docs section linking to the demo and explaining why a custom overlay is needed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: sai chand <60743144+sai6855@users.noreply.github.com>
| const TotalLabel = styled('text')(({ theme }) => ({ | ||
| ...theme?.typography?.body2, | ||
| fontWeight: 600, | ||
| stroke: 'none', | ||
| fill: (theme.vars || theme)?.palette?.text?.primary, | ||
| dominantBaseline: 'central', | ||
| })); |
| const TotalLabel = styled('text')(({ theme }) => ({ | ||
| ...theme?.typography?.body2, | ||
| fontWeight: 600, | ||
| stroke: 'none', | ||
| fill: (theme.vars || theme)?.palette?.text?.primary, | ||
| dominantBaseline: 'central', | ||
| })); |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: sai chand <60743144+sai6855@users.noreply.github.com>
|
@alexfauquette I think having the prop would be good? Like this is probably a common use-case. Something like the following could work.
|
The issue with the props is the positioning. In a simple case with just one stack colomun like in the demo it's ok. It becomes less obvious when
The demo has the advenatge to be failry easy to read and a good starting point for anyone who want to do a more complex one |
preview: https://deploy-preview-22879--material-ui-x.netlify.app/x/react-charts/bars/#stack-total-labels
closes #19458
Since the barLabel slot was introduced, a separate prop no longer seems necessary. Therefore, I went with a demo implementation instead of adding a new prop as described in the issue.