Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js canvas resize

In (Android WebView HTML5 canvas error) i posted a question regarding plotting graphs using Graph.js library. The problem i have now is that if i call the function to plot the graph multiple times, the canvas resizes every time. Each time the graph is redrawn to the same canvas, its size also changes. I also tried setting the size of the canvas but without success.

What could be the reason? Why does the canvas resize every time?

like image 310
Jaka Avatar asked Nov 07 '13 22:11

Jaka


People also ask

Is chart JS responsive?

Luckily, Chart. js does most of this complex work for us! A Chart. js chart is responsive by default, but with one limitation: it maintains its aspect ratio.

Does chart js use canvas?

Let's get started using Chart.js! First, we need to have a canvas in our page. It's recommended to give the chart its own container for responsiveness.


1 Answers

I had a lot of problems with that, because after all of that my line graphic looked terrible when mouse hovering and I found a simpler way to do it, hope it will help :)

Use these Chart.js options:

// Boolean - whether or not the chart should be responsive and resize when the browser does.  responsive: true,  // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container  maintainAspectRatio: false, 
like image 136
NoFlag Avatar answered Oct 15 '22 13:10

NoFlag