I have a small problem with the graphics, what happens is the following, I have a list where the list in each element has a button that shows in a few tabs more information about each element, whenever you click on the button is loaded in a tab the graph that I have made, the question is that this graph every time I show it once and return to the list to look at another item the graph is recharged but on top of the one that already existed, some help?
I have read that it can be the canvas, but I do not know how to clean it, I appreciate the help
I add the requested information regarding the code:
I have the code with which I graph:
require(['assets/bower_components/chart.js/dist/Chart.min.js'], function(Chart){
var ctx = $("#myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
borderWidth:2,
labels: that.label,
datasets: [{
data: that.arrayValorSolicitud
}
]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
})
I have the element that I want when the click is created the graphic based on the previous code
<a target="_self" href="#infoPersonal" aria-controls="infoPersonal" role="tab" data-toggle="tab" ng-click="formCtrl.getCredito(credit); formCtrl.getFlujoCaja(credit)" id="prueba"><span class="botonSiguiente glyphicon glyphicon-arrow-right btn-lg"></span></a>
And I have the element where the graphic is reflected
<canvas id="myChart" width="auto" height="auto"></canvas>
It must be kept in mind that it is a list that is filled using angular and consuming web service, each item that is created has that label that corresponds to a button, where each button is clicked on that button create the graph, when I give any one but that is the first to be clicked is perfect graph, but when I return to the list and clickeo another the graph is shown above the previous one, it is not of more obvious to indicate that the graph is is filling in based on two arrays one is arrayValorSolicitud [] and the other is label [], both must be restarted just as the graph is cleaned