Chartjs-Updating Chart.js with Json

0👍

I actually do not clearly understand the issue but once I faced the issue that I have to update the graph data every time when the button is clicked by the user. So for that, I just normally get the data from API and just put it on my graph js but sometimes it shows and sometimes it is not showing then I fixed that issue by removing the graph div and again appending it and reinitializing the graph once the button is clicked. I don’t that if it fixed your issue or not but in my case it runs perfectly. I’ll some sample code of my work
Here is my HTML code:

<div id="topModelGraph" class="height-400">
 <canvas id="top-model"></canvas>
</div>

This is my js Code:

 $('div#topModelGraph').empty();
 $('div#topModelGraph').append('<canvas id="top-model"></canvas>');
 var ctx = document.getElementById('top-model');
 var lineChart = new Chart(ctx, config);

0👍

It seems in the code you are not invoking myChart.update() method which will update and re-render the chart, after you click the button.

Leave a comment