Is it possible to change background color of highc

2019-06-23 18:32发布

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?

标签: highcharts
2条回答
Explosion°爆炸
2楼-- · 2019-06-23 19:02

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();
查看更多
淡お忘
3楼-- · 2019-06-23 19:09

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
        });
查看更多
登录 后发表回答