Using 2 variable JSON:Date, Value in chart - Javascript highcharts

Javascript examples for highcharts:Chart Json Data

Description

Using 2 variable JSON:Date, Value in 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">
      var chart;/*from   ww  w.  j a  v a 2  s . c  o m*/
      $(document).ready(function () {
          var data = [{
              eDate: "2015-02-03",
              usLevel: "2"
          }, {
              eDate: "2015-03-11",
              usLevel: "5"
          }, {
              eDate: "2015-03-25",
              usLevel: "8"
          }];
          var options = {
              chart: {
                  renderTo: 'container',
                  type: 'line'
              },
              title: {
                  x: -20 //center
              },
              subtitle: {
                  text: '',
                  x: -20
              },
              xAxis: {
                  categories: []
              },
              yAxis: {
                  title: {},
                  plotLines: [{
                      value: 0,
                      width: 1,
                      color: '#808080'
                  }]
              },
              legend: {
                  layout: 'vertical',
                  align: 'right',
                  verticalAlign: 'top',
                  x: -10,
                  y: 100,
                  borderWidth: 0
              },
              series: []
          };
          options.chart.renderTo = 'container';
          options.title.text = 'Historical Data';
          options.yAxis.title.text = 'Stage';
          var dataSeries = {data: []};
          data.forEach(function (va) {
              options.xAxis.categories.push(va.eDate);
              dataSeries.data.push(parseFloat(va.usLevel));
          })
          options.series.push(dataSeries);
          chart = new Highcharts.Chart(options);
          console.log(options);
      });

      </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