Google Chart API - Add percentage to pie chart label - Javascript Google Chart

Javascript examples for Google Chart:Pie Chart

Description

Google Chart API - Add percentage to pie chart label

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  w ww .  j  a v a 2s  .c o m
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Phase', 'link', 'percentage'],
          ['Phase 1 25%', '/link1', 25],
          ['Phase 2 25%', '/link2', 25],
          ['Phase 3 50%', '/link3', 50],
        ]);
        var view = new google.visualization.DataView(data);
        view.setColumns([0, 2]);
        var options = {
               pieSliceText: 'label',
          tooltip: {trigger: 'none'},
               slices: {
               0: { color: 'yellow', },
                     1: { color: 'green' },
               2: { color: 'grey' }
               },
        };
      var chart = new google.visualization.PieChart( document.getElementById('piechart'));
        chart.draw(view, options);
        var selectHandler = function(e) {
         window.location = data.getValue(chart.getSelection()[0]['row'], 1 );
        }
        // Add our selection handler.
        google.visualization.events.addListener(chart, 'select', selectHandler);
      }
    }

      </script> 
   </head> 
   <body> 
      <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
      <div id="piechart" style="width: 900px; height: 500px;"></div>  
   </body>
</html>

Related Tutorials