I'm trying to update my pie chart (using Chart.js) every time an input field is modified. I am doing this by replacing the existing graph with an empty canvas and then redrawing it. This is working, but causing me to get a "TypeError: Cannot read property 'currentStyle' of null".
The code is below,
function drawSummaryPie() {
$('#myChart').replaceWith('<canvas id="myChart" width="200" height="200"></canvas>');
draw();
}[enter image description here][1]
Error :
and any help would be appreciated!
HTML:
<div id="line_chart" style="padding-bottom: 20px;">
<canvas id="chartJSContainer" height="100"></canvas>
</div>
JS :
$('#chartJSContainer').remove();
$('#line_chart').html('<canvas id="chartJSContainer" height="100"></canvas>');
var linectxx = document.getElementById('chartJSContainer').getContext('2d');
var newlinechart = new Chart(linectxx, options1);
Its working for me. Used .html() instead of .append :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With