TypeError: Cannot read property currentStyle 'null in chart.js

I am trying to update a pie chart (using Chart.js) every time an input field changes. I do this by replacing the existing graph with a blank canvas and then redrawing it. This works, but causing me to get "TypeError: Can not read property" currentStyle "null".

The code is below,

function drawSummaryPie() {
$('#myChart').replaceWith('<canvas id="myChart" width="200" height="200"></canvas>');
draw(); 
}[enter image description here][1]   

      

Mistake: enter image description here

and any help would be appreciated!

+3


source to share


1 answer


I solve this problem by putting the canvas inside a div, for example:

<div style="width:75%;">
    <canvas id="canvas"></canvas>
</div>

      



or in JS:

var div = document.createElement('div');
div.style = "width:100%;";
canvas = document.createElement('canvas');
div.appendChild(canvas);

      

0


source







All Articles