How to resize canvas with Chart.js and JavaScript?

Spread the love

To resize canvas with Chart.js and JavaScript, we set the width and height properties.

For instance, we write

const ctx = document.getElementById("canvas").getContext("2d");
ctx.canvas.width = 300;
ctx.canvas.height = 300;
const myDoughnut = new Chart(ctx).Doughnut(doughnutData);

to get the canvas with getElementById and get its context with getContext.

And then we set its width and height to set its width and height.

Next, we create a donughnut chart with the canvas with the Doughnut function.

Leave a Reply

Your email address will not be published. Required fields are marked *