Chartjs-Chart.JS canvas gets larger every time drawn

0👍

You can’t destroy myLine before you define it.
you don’t have canvas defined either.

I suggest you do the following:

var canvas = ("canvas")[0].getContext("2d");
    var myLine = new Chart(canvas).Bar(barChartData);
    canvas.width = 800;
    canvas.height = 500;

0👍

I read the Documentation of ChartJS and I could not find anything relates to Resizing the chart. So I tried every possible ways. But this simple thing worked out for me well. Now I have sized the canvas element as I prefer.

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 and allows for dynamic, scriptable rendering of 2D shapes and bitmap images. 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>

Leave a comment