Home forums Using CanvasJS Help with Dynamic chart, please !!! Reply To: Help with Dynamic chart, please !!!

#10564

cool1
Member

Hi,

I am a novice user and have put up the below code with help from some forums. I am able to get json data from a php page and display the same on a chart using document ready function. However, now i am pulling json data from another php page and trying to redraw it on the same chart on a button click event. I am new to web programming and have been unsuccessful in tracing where I am going wrong. Could you please review the code and suggest. I have registered just now and in haste didnt find the new post option so appended below this post which is somewhat relevant.

//When page is loaded the below function loads the chart with a default product rating

$(document).ready(function () {

$.getJSON(“ratingsdata.php”, function (result) {

var 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) {

data: [

{
dataPoints: result
}
]

});

alert(“success”);
chart.options.data.push(result);
chart.render();
};

//Function for button click event

document.getElementById(“viewratings”).onclick = function(){
updateChart(); }

});

});