Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js bar chart is overflowing its containing element

Chart.js

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 the responsive option is set to true.

It also doesn't matter what I set box-sizing to. What's the purpose of the responsive option if not to fit it's container?

like image 525
corysimmons Avatar asked Jul 27 '14 04:07

corysimmons


2 Answers

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

:)

like image 113
neaumusic Avatar answered Sep 27 '22 23:09

neaumusic


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;
like image 45
Shripad Bhat Avatar answered Sep 28 '22 00:09

Shripad Bhat