Set height of chart in Chart.js
Seems like var ctx = $('#myChart');
is returning a list of elements. You would need to reference the first by using ctx[0]
.
Also height is a property, not a function.
I did it this way in my code:
var chartEl = document.getElementById("myChart");
chartEl.height = 500;
The easiest way is to create a container for the canvas and set its height:
<div style="height: 300px">
<canvas id="chart"></canvas>
</div>
and set
options: {
responsive: true,
maintainAspectRatio: false
}
If you disable the maintain aspect ratio in options then it uses the available height:
var chart = new Chart('blabla', {
type: 'bar',
data: {
},
options: {
maintainAspectRatio: false,
}
});