show only last new added x points on line chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

show only last new added x points on line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript">
$(function () {/*  ww w . j  a  v  a2s .co  m*/
    $('#container').highcharts({
        series: [{
            data: [7.0, 6.9, 9.5, 14.5, 18.2]
        }]
    });
    var chart = $('#container').highcharts();
    var numberOfPointsToShow = 5;
    setInterval(function() {

        chart.series[0].addPoint(Math.random() * 25);

        var lastPoint = chart.series[0].data.length - 1;

        chart.xAxis[0].setExtremes(
                lastPoint - (numberOfPointsToShow - 1), // min
                lastPoint); // max
    }, 1000);
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials