Home Forums Chart Support how to autoupdate graph when new value added in database

how to autoupdate graph when new value added in database

Viewing 2 posts - 1 through 2 (of 2 total)
  • #25014

    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
    }

    #25049

    @dataninja,

    Please check this sample project to create dynamic charts using data from MySQL database in PHP with CanvasJS Charts.


    Shashi Ranjan
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.