Mouse out event handler in Google chart script - Javascript Google Chart

Javascript examples for Google Chart:Chart Configuration

Description

Mouse out event handler in Google chart script

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Bar Chart Example</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}"></script> 
      <div id="piechart" style="width: 900px; height: 500px;"></div> 
      <script type="text/javascript">
      google.setOnLoadCallback(drawChart);
      function drawChart() {/*ww w .jav  a2  s .  c  o m*/
         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',
        legend: 'none',
        pieSliceText: 'percentage',
        slices: { }
    };
    var chart = new   google.visualization.PieChart(document.getElementById('piechart'));
    chart.draw(data, options);
    google.visualization.events.addListener(chart, 'onmouseout', function(e) {
        var slices = options.slices ;
        slices[e.row] = {};
        options['slices'] = slices;
        chart.draw(data, options);
      }
    );  // mouse out end
   google.visualization.events.addListener(chart, 'onmouseover', function(e) {
           var sliceid= e.row;
           var slices = options.slices ;
           if(slices.hasOwnProperty(e.row)){
               if(slices[e.row].hasOwnProperty('offset')) return false
           }
       slices[e.row] = {offset:0.2};
       options['slices'] = slices;
       chart.draw(data, options);
           }
    );   // mouse over end
      }

      </script>  
   </body>
</html>

Related Tutorials