Use data from Javascript array - Javascript highcharts

Javascript examples for highcharts:Chart Data

Description

Use data from Javascript array

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> 
      <script src="https://code.highcharts.com/stock/highstock.js"></script> 
      <script src="https://code.highcharts.com/stock/modules/exporting.js"></script> 
      <div id="container" style="height: 400px"></div> 
      <script type="text/javascript">
// data/*from w w  w  .j  a v  a 2  s  .c o  m*/
var data = [
  [1501624793000, 3389],
  [1501883993000, 4045],
  [1501970397000, 6572],
  [1502056798000, 5836],
  [1502143193000, 4736],
  [1502229588000, 6629],
  [1502315996000, 3981],
  [1502402391000, 4424],
];
Highcharts.each(data, function(d, i) {
  var realTime = d[0],
    date = Highcharts.dateFormat('%Y:%m:%d:%H:%M:%S:%L', realTime).split(':'),
    day = (+date[2]) + ((+date[3]) > 19 ? 1 : 0);
  data[i].push(realTime);
  data[i][0] = Date.UTC(+date[0], +date[1], day);
});
// create the chart
Highcharts.stockChart('container', {
  series: [{
    type: 'column',
    data: data,
    keys: ['x', 'y', 'realTime'],
    tooltip: {
      pointFormat: '{point.realTime: %Y.%m.%d %H:%M:%S}'
    }
  }]
});

      </script>  
   </body>
</html>

Related Tutorials