I\'m trying out the example code for Chart.js given in the docs.
Width and height is specified inline on the canvas element at 400px/400px.
But when renderin
Use this, it works fine.
<canvas id="totalschart" style="height:400px;width: content-box;"></canvas>
and under options
,
responsive:true,
You can override the canvas style width !important ...
canvas{
width:1000px !important;
height:600px !important;
}
also
specify responsive:true,
property under options..
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
update under options added : maintainAspectRatio: false,
link : http://codepen.io/theConstructor/pen/KMpqvo
In my case, passing responsive: false
under options solved the problem. I'm not sure why everybody is telling you to do the opposite, especially since true is the default.
You can change the aspectRatio
according to your needs:
options:{
aspectRatio:4 //(width/height)
}
Works for me too
responsive:true
maintainAspectRatio: false
<div class="row">
<div class="col-xs-12">
<canvas id="mycanvas" width="500" height="300"></canvas>
</div>
</div>
Thank You
The below worked for me - but dont forget to put this in the "options" param.
var myChart = new Chart(ctx, {
type: 'line',
data: data,
options: {
maintainAspectRatio: false,
responsive:true,
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});