Add tooltip to legend in highcharts when hovering

前端 未结 3 1236
孤独总比滥情好
孤独总比滥情好 2020-12-03 18:09

Id like to let the user know that he can remove items from the legend by simply clicking on them. To some, this may be intuitive but others may not know that they can do tha

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 18:54

    Highcharts doesn't have built-in tooltip for item legend, but still you can create your own tooltip for that. It's simple to add custom events to legendItem (mouseover and mouseout for example) and show that tooltip.

    See example how to add events to elements in Highcharts: http://jsfiddle.net/rAsRP/129/

            events: {
                load: function () {
                    var chart = this,
                        legend = chart.legend;
    
                    for (var i = 0, len = legend.allItems.length; i < len; i++) {
                        (function(i) {
                            var item = legend.allItems[i].legendItem;
                            item.on('mouseover', function (e) {
                                //show custom tooltip here
                                console.log("mouseover" + i);
                            }).on('mouseout', function (e) {
                                //hide tooltip
                                console.log("mouseout" + i);
                            });
                        })(i);
                    }
    
                }
            }
    

提交回复
热议问题