简体   繁体   English

高图-将颜色悬停在饼图中的切片上时更改颜色

[英]Highcharts - change color while hovering over a slice in pie chart

I have a simple pie chart that's green and I would like to change the slice color to red once you hover over it. 我有一个简单的绿色饼图,将鼠标悬停在上面时,我想将切片颜色更改为红色。 I'm trying to do that with the API, but it's not working... 我正在尝试使用API​​进行此操作,但无法正常工作...

Here's the jsfiddle: http://jsfiddle.net/TdKGW/4/ 这是jsfiddle: http : //jsfiddle.net/TdKGW/4/

Trying to do this via the states/hover method, but it's not working: 尝试通过状态/悬停方法执行此操作,但不起作用:

            states: {
                hover: {
                    brightness: 0,
                    color: 'red'                        
                }
            }

Any idea on how I can have the slice that you're hovering over (or mouseover) have a red fill? 关于如何让您悬停的切片(或将鼠标悬停在上面)的任何想法有红色填充吗? And it would change back to green once you mouseout. 一旦将鼠标移出,它就会变回绿色。

Thanks 谢谢

You can catch mouseOver event on point and set fill, then catch mouseOut of series, and "recover color" by setting default. 您可以在点上捕获mouseOver事件并设置填充,然后捕获mouseOut系列,并通过设置默认值来“恢复颜色”。

plotOptions: {
            series: {
                states: {
                    hover: {
                        enabled: false
                    }
                },
                point: {
                    events: {
                        mouseOver: function () {
                            this.graphic.attr({
                                fill: 'red'
                            });
                        }
                    }
                },
                events: {
                    mouseOut: function () {
                        var serie = this.points;

                        $.each(serie, function (i, e) {
                            this.graphic.attr({
                                fill: '#CCCCCC'
                            });
                        });
                    }
                }
            }
        },

Example: http://jsfiddle.net/r6p7E/6/ 示例: http//jsfiddle.net/r6p7E/6/

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

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