Accepted answer

i also needed a responsive canvas and had this issue. this was my fix:

    <canvas id="chart"></canvas>

since chart.js scales the canvas to the width of the container, ignoring the padding, i just wrapped the canvas in a div. the div scales to the container with padding, respecting the padding, and then the responsive chart.js canvas scales to the div.


"if for example, you wanted all charts created to be responsive, and resize when the browser window does, the following setting can be changed:" = true;

"now, every time we create a chart, options.responsive will be true."



i wrapped the in and then used this css.

.chart-container {

this keeps it padded from the edges and responsive. i used 2% but you can use whatever percentages suit your layout.


in your jsfiddle example change the responsive attribute to false:

var options = {
    maintainaspectratio: true,
    responsive: false

the previous setting added a additional 30px to both the height and width when you inspect the element using chrome dev tools. because of the size of the canvas it should not be problematic when it comes to resizing of the canvas.

jsfiddle example


a better solution is to use .container {box-sizing: border-box;}


i too googled for this problem and ended up with a simple solution.

i added height so that it automatically adjust the width accordingly and show it in a nicer way. if u really want you could add width too. the canvas element is part of html5.

it does not allow you to input values with px. so ignore that and just type tha numerical value u need.

 <canvas id="mychart" height="80"></canvas>

Related Query

More Query from same tag