So maybe I’m doing something wrong but as far as I can gather, the responsive feature in the latest version doesn’t allow you to use fixed height charts whilst utilizing the responsive width feature.
I wanted to make a container of 100%% width and 400px height although of course chart.js responsive height overrides anyway I add.
Any quick fix for this?
I was struggling with this earlier today, then came across the recently added
maintainAspectRatio
option (997a216). Setting it to false, along withresponsive: true
will redraw the canvas within a fixed height container correctly.JSFiddle Example
it took my lot of time in trying to lay the chart inside a fixed height container. Just now I found this issue, thanks!
It would be great if maintainAspectRatio and responsive options could be made false and true by default, respectively.
Display:block;
The height property is getting increased infinitely
I had the same problem with excessive high on a linechart. I discovered that the problem was that I had the width of the canvas at 100%% and I solved it by applying the property “width: content-box;” Since my canvas is inside a box block. I hope you can solve your problem in this way. I did not have to touch responsive or maintainAspectRatio, I kept them true
@glavrjk Thank you for that solution, it fixed it for me! I simply did this:
<div><canvas id="totalschart" style="height:400px;width: content-box;"></canvas></div>
With “responsive: true” and “maintainAspectRatio: false” and now it correctly displays as 400px high.
@enrimarfe or you can set the
max-height
of the canvas to limit the height calculation.This solved my issue with the height calculation going way high!