Home Forums Chart Support Shift live graph

Shift live graph

Viewing 3 posts - 1 through 3 (of 3 total)
  • #39988

    Hello,

    I am trying to insert this code:

    if (dps.length > 10 )
    {
    dps.shift();
    }

    a my chart code below so data points don’t keep accumulating, and to remove old values ​​from the beginning of the array.

    I tried to modify dps and put different name and place it in different places in my code but it doesn’t work.

    Thank you in advance for your help.

    "window.onload = function () {
    var chart = new CanvasJS.Chart("chartContainer",{
    title:{
    text:"Vent Km/h"
    },
    axisX: {
    title: "Heure"
    },
    axisY: {
    title: "Vent Km/h"
    },
    data: [{
    type: "line",
    dataPoints : [],
    },
    ]
    });
    
    $.getJSON("service.php", function(data) {  
        $.each((data), function(key, value){
            chart.options.data[0].dataPoints.push({label: value[0], y: parseInt(value[1])});
    
        });
    
        chart.render();
        updateChart();
    });
    
    function updateChart() {
        $.getJSON("service.php", function(data) {       
            chart.options.data[0].dataPoints = [];
    
            $.each((data), function(key, value){
                chart.options.data[0].dataPoints.push({label: value[0], y: parseInt(value[1])});
    
            });
    
            chart.render();
            updateChart();
        });
    }
    
    setInterval(function(){updateChart()}, 2000);
    }"
    #40007

    @rafdu01,

    Since you are using chart options to access the datapoints, the code must be re-written to fit your scenario as shown in the code snippet below,

    if (chart.options.data[0].dataPoints.length > 10 ) {
       chart.options.data[0].dataPoints.shift();
     }

    If this doesn’t solve your requirement, kindly share a sample project over Google Drive or Onedrive reproducing the issue you are facing, so that we can look into the code, run it locally to understand the scenario better, and help you out.


    Adithya Menon
    Team CanvasJS

    #40009

    Hello,
    Thank you very much it works.

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

You must be logged in to reply to this topic.