Chart.js bar chart is overflowing its containing element
Solution 1
As with most CSS, the answer is to use another wrapper!
I had the same problem (and I'm using box sizing)
Just put one div around your canvas! (the divs will inherit the box sizing)
<div>
<canvas></canvas>
</div>
Good luck
:)
Solution 2
This will solve the issue
Javascript:
new Chart(ctx).Line(data, {
responsive:true,
maintainAspectRatio: false
});
ES6
Chart.defaults.global.responsive = true;
Chart.defaults.global.maintainAspectRatio = false;
corysimmons
I'm a fullstack web-developer currently specializing in React, React Native, Node, and Typescript. I have over 20 years of experience making websites (really, I can pull up my FF7 website from 1997) and over a decade of professional experience. My open source libraries have thousands of Github Stars and have been downloaded millions of times. I've written for just about every big publisher in the industry (Envato, CSS Tricks, a book for Packt Publishing, .net Magazine, etc.) and spoken at a few frontend conferences. Check out my website at corysimmons.com and feel free to reach out to me on there.
Updated on June 21, 2022Comments
-
corysimmons almost 2 years
I can't get this stupid chart to stay in its container when
padding
has been applied to the container. It doesn't matter if theresponsive
option is set totrue
.It also doesn't matter what I set
box-sizing
to. What's the purpose of theresponsive
option if not to fit it's container?