pie chart rendering with legend - Javascript highcharts

Javascript examples for highcharts:Pie Chart

Description

pie chart rendering with legend

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <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  . j a v  a  2s . co m
    $('#container').highcharts({
        chart: {
            type: 'pie'
        },
        title: {
            text: ''
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        legend: {
            layout: 'horizontal',
            verticalAlign: 'top'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: false
                },
                showInLegend: true
            }
        },
        series: [{
            type: 'pie',
            innerSize: '80%',
            name: 'Browser share',
            data: [
                ['Firefox', 45.0],
                ['IE', 26.8], {
                    name: 'Chrome',
                    y: 12.8
                }, ['Safari', 8.5],
                ['Opera', 6.2],
                ['Others', 0.7]
            ]
        }]
    });
    // the button handler
    $('#button').click(function () {
        var chart = $('#container').highcharts();
        chart.series[0].remove();
        chart.addSeries({
            size: '70%',
            innerSize: '50%',
            data: [194.1 * Math.random(), 95.6 * Math.random(), 54.4 * Math.random(), 29.9 * Math.random(), 71.5 * Math.random(), 106.4 * Math.random(), 129.2 * Math.random(), 144.0 * Math.random(), 176.0 * Math.random(), 135.6 * Math.random(), 148.5 * Math.random(), 216.4 * Math.random()]
        });
    });
});

      </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="height: 400px"></div> 
      <button id="button" class="autocompare">Add series</button>  
   </body>
</html>

Related Tutorials