Search code examples
phphighchartslive

Highchart live with 2 graphs - shift trouble


I use LIVE Highchart with 2 live graphs. The chart should display only 5 datapoints at on time. Therefore is the shift-argument

 var series1 = chart.series[0];
 shift1 = series1.data.length > 5;       
 series1.addPoint(point1, true, shift1);

So when point six arrives, point one is thrown away. But when i disable a series for a while ... and after enabling it again ... there was no shift.

http://www.abload.de/img/errorh5kko.jpeg

I reproduced it on jsfiddle for you

http://jsfiddle.net/yeDYr/1/

So both livegraphs no matter whether enabled or disabled should be shifted.


Solution

  • Looks like a bug in Highcharts to me. As a workaround, just .show() the series, then hide() it (if needed). Highcharts seems to be able to do this without any visible flickering.

    // the button action
    $('#button1').click(function() {
    
        var point1 = Math.random() * 10;
        var point2 = Math.random() * 10;
    
        var series1 = chart.series[0];
        shift1 = series1.data.length > 5;
    
        isVisible = series1.visible;
        if (!isVisible) series1.show();
        series1.addPoint(point1, true, shift1);
        if (!isVisible) series1.hide();
    
        var series2 = chart.series[1];
        shift2 = series2.data.length > 5;
    
        isVisible = series2.visible;
        if (!isVisible) series2.show();
        series2.addPoint(point2, true, shift2);
        if (!isVisible) series2.hide();
    });
    

    Updated fiddle.