简体   繁体   English

在Highstock / Highcharts中设置rangeSelector容器的背景色

[英]Setting background color of rangeSelector container in Highstock/Highcharts

I have a Highcharts chart and I need to modify the rangeSelector section. 我有一个Highcharts图表,需要修改rangeSelector部分。 I've been able to format some of the buttons and input boxes, but I'd like to specify the background color of the entire range selection area . 我已经能够格式化一些按钮和输入框,但是我想指定整个范围选择区域的背景色 Here's an image of the area I'm talking about (red outline). 这是我正在谈论的区域的图像(红色轮廓)。

在此处输入图片说明

Additionally, here's a JSFiddle for that particular chart. 此外,这是该特定图表的JSFiddle

As far as I can tell, there are no options that would allow me to select that section directly listed in the documentation . 据我所知,没有任何选项可以让我选择直接在文档中列出的部分。

I've also tried making a div and positioning it absolutely over the range selector, and then elevating the elements inside the range selector with the Highcharts zIndex attribute, but that doesn't appear to work. 我还尝试制作div并将其绝对定位在范围选择器上,然后使用Highcharts zIndex属性将范围选择器内的元素提升,但这似乎不起作用。

You can use Highcharts.SVGRenderer class to render a rect element, which will be a background for the rangeSelector : 您可以使用Highcharts.SVGRenderer类来渲染rect元素,该元素将作为rangeSelector的背景:

chart: {
    events: {
        load: function() {
            var rangSel = this.rangeSelector.group.getBBox();

            this.renderer.rect(
                rangSel.x,
                rangSel.y,
                rangSel.width,
                rangSel.height
            ).attr({
                fill: 'red'
            }).add();
        }
    }
}

Live demo: http://jsfiddle.net/BlackLabel/kpbxya8s/ 现场演示: http : //jsfiddle.net/BlackLabel/kpbxya8s/

API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#rect API参考: https//api.highcharts.com/class-reference/Highcharts.SVGRenderer#rect

Found a good workaround in case anyone runs into this issue as well. 找到了一个很好的解决方法,以防任何人也遇到此问题。 Set the chart's overall backgroundColor to a linear gradient with three stops (the first two are your initial color). 将图表的总体backgroundColor设置为带有三个停止点的线性渐变(前两个是您的初始颜色)。 Here's an example where the top bar needs to be 54px tall. 这是一个示例,其中顶部栏的高度必须为54px。

backgroundColor: {
  linearGradient: [0, 0, 0, 54, 0, 54],
  stops: [
    [0, '#707070'],
    [1, '#707070'],
    [2, '#e2e2e2']
  ]
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM