Fill data from Json array to chart - Javascript highcharts

Javascript examples for highcharts:Chart Json Data

Description

Fill data from Json array to 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 () {/* w ww  .j  av  a2 s  .c  o  m*/
    //$.getJSON
    //parser
    var data = [{
        "metier": "Administratif",
        "total": 197555
    }, {
        "metier": "Canalisateur",
        "total": 4717
    }, {
        "metier": "Carreleur",
        "total": 15513
    }];
    var output = [];
    $.each(data,function(i,d){
        output.push({
            name: d.metier,
            y: d.total
        });
    });
    $('#container').highcharts({
        chart:{
            type:'column'
        },
        xAxis:{
            type:'category'
        },
        series: [{
            name: 'Tokyo',
            data: output
        }]
    });
});

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