Highcharts Pie with Legends Chart

In the previous chapters, we learned how to setup highcharts library and how to create a chart with required configurations using highcharts library in our webpage. Now, we will learn how to create a pie chart with legends using highcharts library with examples.

Highcharts Pie with Legends Chart Example

Following is the example of creating a pie chart with legends by setting the required chart properties using highcharts library.

 

<html>

<head>

    <title>Highcharts Pie with Legends Chart</title>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

    <script src="https://code.highcharts.com/highcharts.js"></script>

    <script src="https://code.highcharts.com/modules/exporting.js"></script>

    <script src="https://code.highcharts.com/modules/export-data.js"></script>

    <script type="text/javascript">

        $(function() {

            Highcharts.chart('container', {

                chart: {

                    plotBackgroundColor: null,

                    plotBorderWidth: null,

                    plotShadow: false,

                    type: 'pie'

                },

                title: {

                    text: 'Browser market shares in January, 2018'

                },

                tooltip: {

                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'

                },

                plotOptions: {

                    pie: {

                        allowPointSelect: true,

                        cursor: 'pointer',

                        dataLabels: {

                            enabled: false

                        },

                        showInLegend: true

                    }

                },

                series: [{

                    name: 'Brands',

                    colorByPoint: true,

                    data: [{

                        name: 'Chrome',

                        y: 61.41,

                        sliced: true,

                        selected: true

                    }, {

                        name: 'Internet Explorer',

                        y: 11.84

                    }, {

                        name: 'Firefox',

                        y: 10.85

                    }, {

                        name: 'Edge',

                        y: 4.67

                    }, {

                        name: 'Safari',

                        y: 4.18

                    }, {

                        name: 'Other',

                        y: 7.05

                    }]

                }]

            });

        });

    </script>

</head>

<body>

    <div id="container" style="width: 100%; height: 400px;"> </div>

</body>

</html>

If you observe the above example, we created a pie chart with legends using highcharts library with required properties.

 

When we execute the above highcharts example, we will get the result like as shown below.

 

Highcharts Pie Chart with Legends Example Result

 

This is how we can create a pie chart with legends using highcharts library with required properties.

 
 
 

Topics Covered