Pie Chart with Legend

Pet Preferences

by Emre Bolat

HTML

<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; max-width: 600px; margin: 0 auto"></div>

JavaScript

$(function () {

    $(document).ready(function () {

        // Build the chart
        $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false,
                type: 'pie'
            },
            title: {
                text: 'Pet Preferences'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: false
                    },
                    showInLegend: true
                }
            },
            series: [{
                name: 'Pets',
                colorByPoint: true,
                data: [{
                		name: 'Cats',
              		  y: 39.38
            		}, {
                		name: 'Dogs',
                		y: 35.12,
                		sliced: true,
                		selected: true
            		}, {
                		name: 'Bunnies',
                		y: 15.02
            		}, {
                		name: 'Fish',
                		y: 5.33
            		}, {
                		name: 'Hamsters',
                		y: 3.29
           		 }, {
                		name: 'Ferrets',
                		y: 1.83
            		}]
            }]
        });
    });
});