Export JSON Data to Pie chart - Javascript highcharts

Javascript examples for highcharts:Pie Chart

Description

Export JSON Data to Pie 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://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
$(function () {//from   www .jav  a2  s  .c o m
    var chart;
    var myJson = [{
        "Buch": "0528713FHVR ",
        "Anzahl": 3
    }, {
        "Buch": "0657222FHVR",
        "Anzahl": 2
    }, {
        "Buch": "A10055035",
        "Anzahl": 2
    }, {
        "Buch": "0657223FHVR",
        "Anzahl": 1
    }, {
        "Buch": "062729XFHVR",
        "Anzahl": 1
    }]
    $(document).ready(function () {
        var options = {
            chart: {
                renderTo: 'container',
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'My PIE chart'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                percentageDecimals: 1
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        formatter: function () {
                            return '<b>' + this.point.name + '</b>: ' + this.percentage + ' %';
                        }
                    }
                }
            },
            series: []
        };
        var seriesNew = {
            type: 'pie',
            name: 'Some series name',
            data: []
        };
        jQuery.each(myJson, function (itemNo, item) {
            seriesNew.data.push({
                x: item.Buch,
                y: item.Anzahl
            })
        });
        options.series.push(seriesNew);
        chart = new Highcharts.Chart(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: 400px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials