score:2

Accepted answer

I have been able to solve it. Actually I didn't use my variable chart1 correctly for the function below. It has t be changed as such:

var chart1;

/**
 * Request data from the server, add it to the graph and set a timeout
 * to request again
 */
function requestLightData() {
    $.ajax({
        url: '/live-data',
        success: function(point) {
            var series = chart1.series[0],
                shift = series.data.length > 20; // shift if the series is
                                                 // longer than 20

            // add the point
            chart1.series[0].addPoint(point, true, shift);

            // call it again after one second
            setTimeout(requestLightData, 1000);
        },
        cache: false
    });
}

I also merged the two js scripts into, ie I added all that was in highchartsTemp.js into highcharts.js and removed the script highchartsTemp.js from my HTML file.


Related Query

More Query from same tag