Skip to content
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

[charts] Bar chart bottom legend is not well positioned #11926

Closed
Sozialarchiv opened this issue Feb 4, 2024 · 4 comments
Closed

[charts] Bar chart bottom legend is not well positioned #11926

Sozialarchiv opened this issue Feb 4, 2024 · 4 comments
Labels
component: charts This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature

Comments

@Sozialarchiv
Copy link

Sozialarchiv commented Feb 4, 2024

Steps to reproduce

Link to live example: (required)

 <BarChart
                xAxis={[{ scaleType: 'band', data: ['group A', 'group B', 'group C'] }]}
                series={[{ data: [4, 3, 5], label: 'aa' }, { data: [1, 6, 3], label: 'bb' }, { data: [2, 5, 6], label: 'cc' }]}
                width={500}
                height={300}
                slotProps={{
                    legend: {position: {horizontal: 'middle', vertical: 'bottom'}}
                }}
            />

Steps:

  1. Bar chart with legend on bottom

Current behavior

Legend is over the chart

grafik

Expected behavior

Legend should be under the chart

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: bar chart legend bottom

@Sozialarchiv Sozialarchiv added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 4, 2024
@michelengelen michelengelen added enhancement This is not a bug, nor a new feature component: charts This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 5, 2024
@michelengelen
Copy link
Member

Thanks @Sozialarchiv for reporting. I have put it on our board to have a look at how we can improve this. Thanks again 🙇🏼

@alexfauquette
Copy link
Member

The issue is that the legend is position relatively to the svg container. It does not take care of the drawing area.

Since you move the legend from the bottom, you can modify the drawing area as follow:

margin={{
      top: 10, // get more space from the top since we don't have legend to display now
      bottom: 75, // Add some space to let the legend be visible
    }}

https://stackblitz.com/edit/react-hsvjub?file=Demo.tsx

@michelengelen
Copy link
Member

Oh, nice! Thanks for the example @alexfauquette

@Sozialarchiv
Copy link
Author

Thank you very much for the good and fast answer.
I will create an pro account to honor your great work.


The issue is that the legend is position relatively to the svg container. It does not take care of the drawing area.

Maybe it would be helpful for others to make this possibility more notable in the doc. For me this ticket is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature
Projects
None yet
Development

No branches or pull requests

3 participants