Hide rest of the region when user clicks pie chart? - Javascript highcharts

Javascript examples for highcharts:Pie Chart

Description

Hide rest of the region when user clicks 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://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript">
$(function () {/*  w  w  w. ja  va 2 s .  co  m*/
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'users location'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                },
                point: {
                    events: {
                        click: function() {
                            var _self = this,
                                undef,
                                method = _self.clicked ? "show" : "hide";
                            Highcharts.each(this.series.data, function(p, i) {
                                if(p !== _self) {
                                    // hide slice
                                    if(p.graphic) {
                                        p.graphic[method]();
                                    }
                                    // hide label
                                    if(p.dataLabel) {
                                         p.dataLabel[method]();
                                    }
                                    // hide connector
                                    if(p.connector) {
                                         p.connector[method]();
                                    }
                                }
                            });
                            _self.clicked = _self.clicked !== undef ? !_self.clicked : true;
                        }
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Africa',   45.0],
                ['Asia',       26.8],
                {
                    name: 'Australia',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                ['Europe',    8.5],
                ['North America',     6.2],
                ['Others',   0.7]
            ]
        }]
    });
});

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

Related Tutorials