how to change bar hover color of highchart dynamically?

ぃ、小莉子 提交于 2019-12-13 04:55:11

问题


I set bar hover color using below code:

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

But how can I change the bar hover color dynamically?


回答1:


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




回答2:


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>
I have done a little bit here. will improve it soon.




回答3:


Simply use point.update(options), where in options you will set new hover color:

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

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



来源:https://stackoverflow.com/questions/30365381/how-to-change-bar-hover-color-of-highchart-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!