Multiple series highstock live chart - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

Multiple series highstock live chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <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() {/* w  ww .ja va  2 s.  c  o m*/
  function requestData() {
    var chart = $('#container').highcharts();
    // Imitate ajax: $.ajax() { .. }:
    var now = +new Date();
    var first_point = [now, Math.random()];
    var points = [
      first_point,
      [now, Math.random()],
      first_point // extra point for navigator
    ];
    // Ajax success body:
    var series = chart.series,
      shift;
    $.each(series, function(i, s) {
        shift = s.data.length > 20;
        s.addPoint(points[i], false, shift);
    });
    setTimeout(requestData, 1000);
    chart.redraw();
  }
  // Create the chart
  $('#container').highcharts('StockChart', {
    chart: {
      events: {
        load: requestData
      }
    },
      navigator: {
       series: {
         data: []
      }
    },
    series: [{
      name: 'Random data',
      data: []
    }, {
      name: 'Random data 2',
      data: []
    }]
  });
});

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

Related Tutorials