Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

chart.js

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 : enter image description here

and any help would be appreciated!

like image 206
AvJoe1029 Avatar asked Mar 08 '23 13:03

AvJoe1029


1 Answers

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 :)

like image 69
Mani K Avatar answered Apr 30 '23 00:04

Mani K