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

Chart is not responsive inside flexbox #11833

Open
jasonpolites opened this issue Jul 10, 2024 · 2 comments
Open

Chart is not responsive inside flexbox #11833

jasonpolites opened this issue Jul 10, 2024 · 2 comments

Comments

@jasonpolites
Copy link

Expected behavior

Chart should be responsive when contained in a div with the prescribed criteria.

Current behavior

I have a layout in my app which uses flex-box to determine the layout of UI elements. The reproducible sample presents a simplified version of this layout. On its own, it may not make sense, but it's a subset of the overall layout that still presents the issue.

The chart does not resize when the size of the containing DIV is changed (e.g through changing the browser window size). To be more precise, it does resize UP (increase), but not DOWN (decrease). If you load the code pen with a smaller window, then drag to increase, you will see the chart expand, but it won't contract when you reduce the window size.

https://codepen.io/jasonpolites/pen/QWXwENB

Reproducible sample

https://codepen.io/jasonpolites/pen/QWXwENB

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v4.4.3

Browser name and version

No response

Link to your project

No response

@bence444
Copy link

Adding max-width: min-content; to the canvas seems to fix the issue (tested in Firefox and Chrome)

@haeythamM
Copy link

I believe this one will work :

use this :
canvas {
border: 1px dotted red;
width: 100% !important;
height: 100% !important;
}
also
.chart-container {
position: relative;
margin: auto;
width: 100% !important;
height: 100% !important;
}
remove this " height: 300px;"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants