On page load my code generates a bar chart via AJAX request:
function docharts(name) {
$.ajax({
url: "sql/getdata.php",
method: "GET",
data: {
staff: name,
},
success: function(data) {
**code to assign labels etc**
var ctx = document.getElementById("summary").getContext("2d");
var myChart = new Chart(ctx, {
showTooltips: true,
type: 'bar',
data: chartdata,
});
myChart.update();
},
error: function(data) {
console.log(data);
}
});
};
This works as expected. However I want to be able to re-run this function with a different variable ("name") and for it to redraw the chart based on this new data.
When I run docharts("foobar") the graph does redraw with the new data, however when the cursor is dragged back outside the canvas it appears to redraw the original graph.
What am I doing wrong?