Subscribe For Free

Wednesday, February 21, 2018

Everything about google pie chart

Its always a good idea to represent your data in a graphical way. here we are explaining how to use google graphs API.
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});

      function drawChart() {

        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]

        var options = {
          title: 'My Daily Activities'

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
    <div id="piechart" style="width: 900px; height: 500px;"></div>

Add these lines in your options variable

1. For 3D model pie chart.
is3D: true,

2. Adding background to pie chart
backgroundColor: 'skyblue',

3. Change legend text color and size
legendTextStyle: { color: 'red', fontSize: 15},

4. Change legend position
you can four different position options-top/bottom/left/right
legend:{ position:'bottom'},

5. Change title text color and size
titleTextStyle: { color: 'red', fontSize:16},

6. Change colors of pie slices
 colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6'],

7. Pie slice text display value and percentage
only for value.
 pieSliceText: 'value',

only for percentage
 pieSliceText: 'percentage',

for value and percentage
 pieSliceText: 'value-and-percentage',

8.Change pie slice(labels) text color and size
pieSliceTextStyle : {fontSize:16, color:'red'},

No comments:

Post a Comment

click it