Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change background color of highcharts?

Tags:

highcharts

Consider the following situation:

    chart.options.chart.backgroundColor= {
        linearGradient: [0, 0, 0, 400],
        stops: [ [0, 'rgb(96, 96, 96)'], 
        [1, 'rgb(16, 16, 16)'] ]
    };
    chart.redraw():

It is all here: http://jsfiddle.net/S8f86/3/

Is it possible to change the background color of the chart with event?

like image 639
Antoan Milkov Avatar asked Dec 26 '22 07:12

Antoan Milkov


2 Answers

You can use chart renderer and svg attribiute.

http://jsfiddle.net/S8f86/4/

this.renderer.button('Change background color', 74, 30, function(){

                        var gradient = {
                            linearGradient: [0, 0, 0, 400],
                            stops: [ [0, 'rgb(96, 96, 96)'], 
                                     [1, 'rgb(16, 16, 16)'] ]
                        };

                    chart.chartBackground.attr({
                        fill:gradient
                    });

                    }).add();
like image 155
Sebastian Bochan Avatar answered Jan 22 '23 03:01

Sebastian Bochan


Highcharts doesn't have an API call to do this. However, you can get at the underlying elements and apply some css styling to them. e.g.

chart.chartBackground.css(
        {
            color: '#555555',
        });

http://jsfiddle.net/xzUcC/

As you are manipulating the dom directly, there is no need to call redraw() on the chart.

As mentioned by another poster, you can do graduated backgrounds as follows:

 var gradient = {
        linearGradient: [0, 0, 0, 400],
                 stops: [ [0, 'rgb(96, 96, 96)'], 
                          [1, 'rgb(16, 16, 16)'] ]
        };
        chart.chartBackground.attr({
                 fill:gradient
        });
like image 30
SteveP Avatar answered Jan 22 '23 03:01

SteveP