简体   繁体   English

如何动态更改highchart的栏悬停颜色?

[英]how to change bar hover color of highchart dynamically?

I set bar hover color using below code: 我使用以下代码设置栏悬停颜色:

plotOptions: {column: {states: {hover: {color: '#000000'}}}}

But how can I change the bar hover color dynamically? 但是,如何动态更改条形悬停颜色?

Defined set of colors, when you load charts every time you will experience a different color of hover effect from the given set 定义的颜色集,每次加载图表时,将遇到与给定颜色集不同的悬停效果颜色

var colors= ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9', 
   '#f15c80', '#e4d354', '#2b908f', '#f45b5b', '#91e8e1'];


    var x = Math.floor((Math.random() * 10) );

            plotOptions: {
                column: {
                    states: {
                        hover: {
                            color: colors[x]                                                           
                        }
                    }

                }
            },

And a fiddle link for details 还有一个小提琴链接以获取详细信息

For future continual work, make a button to trigger chart reload 为了将来继续工作,请单击按钮以触发图表重新加载

create a chart after some event of a drop down from where you want to get color. 在您想要获得颜色的位置发生下拉事件后,创建图表。 something like <select id="idd" onChange="getColor()"> <option value="red">R</option> <option value="green">G</option> </select> 类似于<select id="idd" onChange="getColor()"> <option value="red">R</option> <option value="green">G</option> </select>
I have done a little bit here . 在这里做了一些。 will improve it soon. 会很快改善它。

Simply use point.update(options) , where in options you will set new hover color: 只需使用point.update(options) ,在选项中将设置新的悬停颜色:

    chart.series[0].data[0].update({
        states: {
            hover: {
                color: "red"
            }    
        }
    });

Demo: http://jsfiddle.net/xoje27rt/ 演示: http//jsfiddle.net/xoje27rt/

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

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