I’m new to web and js and i want to make my graph autoupdate whenever a new data enters in database.
kindly please suggest me changes too do.
.js code of graph from followdata.php data is comming
$(document).ready(function(){
$.ajax({
url : “/followdata_temp.php”,
type : “GET”,
success : function(data){
console.log(data);
var time = [];
var temp = [];
for(var i in data){
time.push(“” + data[i].time);
temp.push(“” +data[i].temp);
}
/* for(var j in data){
time.pull(“” + data[j].time);
temp.pull(data[j].temp);
} */
var chartdata = {
labels: time,
datasets: [
{
label: “Temperature”,
fill: false,
lineTension: 0.1,
backgroundColor: “rgba(59, 89, 152 ,0.75)”,
borderColor: “rgba(59, 89, 152, 1)”,
pointHoverBackgroundColor: “rgba(59, 89, 152, 1)”,
pointHoverBorderColor: “rgba(59, 89, 152, 1)”,
data: temp
}
]
};
var ctx = $(“#mycanvas1”);
var LineGraph = new Chart(ctx , {
type: ‘line’,
data: chartdata
});
},
error : function(data) {
}
});
});
window.onload = function (e)
{
RGraph.AJAX.getCSV(“/followdata_temp.php”, myCallback);
setTimeout(window.onload, 2000); // 2000 milliseconds = 2 seconds
}