Putting Values from JSON to Charts - Javascript highcharts

Javascript examples for highcharts:Chart Json Data

Description

Putting Values from JSON to Charts

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">
$(document).ready(function () {
    function getSumErrorSummary(callback) {
        //data from AJAX
        var data = [{/*from   w  w w .  j a  va2s  . c  o  m*/
            "eventName": "ABC",
            "countError": 147391
        }, {
            "eventName": "DEF",
            "countError": 117926
        }];
        //callback
        callback(data);
    }
    var options = {
        chart: {
            type: 'column',
            margin: 75,
            options3d: {
                enabled: true,
                alpha: 10,
                beta: 25,
                depth: 70
            }
        },
        title: {
            text: 'Subtotal Error Summary'
        },
        plotOptions: {
            column: {
                depth: 25
            }
        },
        xAxis: {
            title: {
                text: 'Names'
            }
        },
        yAxis: {
            title: {
                text: 'Sub total'
            }
        },
        series: []
    };
    getSumErrorSummary(function (data) {
        console.log(object) // undefined
        var object = data.map(function (d, i) {
            return {
                name: d.eventName,
                data: [d.countError]
            };
        });
        console.log(object); //[{ name: ... }]
        //set object to options
        options.series = object;
        // call your chart function here
        $('#flot-line-chart').highcharts(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="flot-line-chart" style="min-width: 310px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials