change color while hovering over a slice in pie chart - Javascript highcharts

Javascript examples for highcharts:Chart Color

Description

change color while hovering over a slice in pie chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
$(function () {// ww w.  j a v  a 2  s .c om
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'pie'
        },
        plotOptions: {
            series: {
                states: {
                    hover: {
                        enabled: false
                    }
                },
                point: {
                    events: {
                        mouseOver: function () {
                            this.graphic.attr({
                                fill: 'red'
                            });
                        }
                    }
                },
                events: {
                    mouseOut: function () {
                        var serie = this.points;
                        $.each(serie, function (i, e) {
                            this.graphic.attr({
                                fill: '#CCCCCC'
                            });
                        });
                    }
                }
            }
        },
        tooltip: {
            enabled: false
        },
        series: [{
            data: [{
                name: 'test',
                y: 29.9,
                color: "#CCCCCC",
                active: false
            }, {
                name: 'test2',
                y: 71.5,
                color: "#CCCCCC",
                active: false
            }, {
                name: 'test3',
                y: 106.4,
                color: "#CCCCCC",
                active: false
            }]
        }]
    });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container" style="height: 400px"></div>  
   </body>
</html>

Related Tutorials