You have to replace the link with your PHP file. I have updated updateChart. Finally your code should look like…..
$(document).ready(function() {
var chart;
$.getJSON("ratingsdata.php", function(result) {
chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "Product Ratings"
},
animationEnabled: true,
data: [{
dataPoints: result
}]
});
chart.render();
});
//Function to render the chart on button click
var updateChart = function() {
$.getJSON("selected_product.php", function(result) {
var data = {
dataPoints: result
};
chart.options.data.push(data);
chart.render();
});
};
//Function for button click event
document.getElementById("viewratings").onclick = function() {
updateChart();
}
});