show values on pie Chart - Javascript highcharts

Javascript examples for highcharts:Pie Chart

Description

show values on 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-3.1.1.js"></script> 
      <style id="compiled-css" type="text/css">

#container {/*from  w  w  w .  j a va2  s.c o m*/
   min-width: 300px;
   max-width: 800px;
   height: 300px;
   margin: 1em auto;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
const options = {
  chart: {
    type: 'pie',
    events: {
      load: function() {
        const series = this.series[0];
        const points = series.data;
        const chart = this;
        points.forEach(function(point) {
           if (point.y <= 4) {
            const myOffset = 50;
            const {x: centerX, y: centerY} = point.graphic.attr();
            const {x, y} = point.dataLabel.attr();
            const angle = point.angle;
            point.dataLabel.attr({
              x: x + Math.cos(angle) * myOffset,
              y: y + Math.sin(angle) * myOffset
            });
          }
        });
      }
    }
  },
  title: {
    text: ''
  },
  plotOptions: {
    pie: {
      dataLabels: {
        enabled: true,
        distance: -40,
        formatter: function() {
          return this.y + '%';
        }
      },
      showInLegend: true
    }
  },
  series: [{
    //innerSize: '60%',
    data: [{name: 'Staff Delegation', y:77}, {name: 'AAP', y:11}, {name: 'DCC', y:8.5}, {name: 'Council', y:3.5}]
  }]
}
const chart = Highcharts.chart('container', 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"></div>  
   </body>
</html>

Related Tutorials