Change background color of highcharts on hover - Javascript highcharts

Javascript examples for highcharts:Chart Color

Description

Change background color of highcharts on hover

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-1.9.1.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){// w w w. ja va  2 s .c  om
var columns = [];
$.each([49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4], function (i, v) {
    columns.push({
        y: v
    });
});
var bg = 'red';
$(function () {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            zoomType: 'xy',
            backgroundColor: bg
        },
        plotOptions: {
            series: {
                events: {
                    mouseOver: function () {
                        chart.chartBackground.css({
                            color: 'white',
                        });
                    },
                    mouseOut: function () {
                        chart.chartBackground.css({
                            color: 'red',
                        });
                    }
                }
            }
        },
        title: {
            text: 'Average Monthly Temperature and Rainfall in Tokyo'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        tooltip: {
            shared: true
        },
        xAxis: false,
        yAxis: false,
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 120,
            verticalAlign: 'top',
            y: 100,
            floating: true,
            backgroundColor: '#FFFFFF'
        },
        series: [{
            name: 'Rainfall',
            color: '#E5E5E5',
            type: 'column',
            data: columns,
            tooltip: {
                valueSuffix: ' mm'
            },
        }, {
            name: 'Temperature',
            color: '#9B59B5',
            type: 'spline',
            data: columns,
            tooltip: {
                valueSuffix: '?C'
            }
        }]
    });
});
    });

      </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" style="min-width: 310px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials