如何在Highcharts中的点事件函数中获取图表对象

how to get chart object inside a point event function in Highcharts

本文关键字:获取 函数 对象 事件 Highcharts      更新时间:2023-09-26

即使在单击第二个系列中的点时,我也要如何修改以下示例以获得第一个系列的点值?得到chart对象对我来说就足够了,但我不知道该怎么做(点mouseOut函数this内部指的是point对象,而不是chart对象)。

$(function () {
    $('#container').highcharts({
        plotOptions: {
            series: {
                cursor: 'pointer',
                point: {
                    events: {
                        click: function () {
                            // here I want the y value of the point in the
                            // first series even in this function 
                            // is invoked for the point in the second series
                            alert('value: ' + this.y);
                        }
                    }
                }
            }
        },
        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0]
            },{
            data: [135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }]
    });
});

JSfiddle页面

根据文档:

this关键字指的是Point对象。

Point又具有保持chart:的series属性

series: {
    cursor: 'pointer',
    point: {
        events: {
            click: function() {
                var chart = this.series.chart;
            }
        }
    }
}