How to handle mouse events on axis labels in highcharts

老子叫甜甜 提交于 2019-12-01 09:40:19

问题


How can mouse events be captured on highcharts axis label?
I wish to handle the click event on the labels to perform certain actions

A highchart demo


回答1:


The axis labels can be accessed as yAxis.ticks["x"].label.element. This is the element of the label, and now any event on this element can be handled as follows.

var yAxis = chart.yAxis[0];
var onYaxisRedraw = function() {
    for (var tickPos in yAxis.ticks) {
        var $element=$(yAxis.ticks[tickPos].label.element);
        $element.unbind('click');
        $element.click(function() {
            alert("hi");
        });
    }
}
onYaxisRedraw();
yAxis.redraw(onYaxisRedraw);

It's always better to unbind any previously added handler as same labels may be reused by highchart internally.

Handling/capturing events on axis labels @ jsFiddle



来源:https://stackoverflow.com/questions/12758465/how-to-handle-mouse-events-on-axis-labels-in-highcharts

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