如何在highcharts工具提示中添加onclick事件处理程序


how to add onclick event handler inside highcharts tooltip

我在php应用程序中使用highcharts (Line)。我想在工具提示中使用onclick事件处理程序来打开模态对话框。但我没有找到任何解决方案,即使在高图中,也没有工具提示项目可用的单击事件。我还在工具提示中使用了formatter选项,但它不起作用。请帮我解决这个问题

我正在尝试这个

tooltip: {
    useHtml: true,
    formatter: function () {
        var s = '<b>' + this.x + '</b>';
        $.each(this.points, function (i, point) {
            s += '<br/><span style="color:' + point.series.color + '">'u25CF</span>'n' <span onclick="my_function();">Click Me</span> ' + point.series.name + ': ' + point.y;
        });
        return s;
    },
    shared: true
}

但是my_function没有调用当我点击" click Me"

我从highcharts得到了查询的答案

tooltip: {
    useHTML: true,
    formatter: function () {
        var s = '<b>' + this.x + '</b>';
        $.each(this.points, function (i, point) {
            s += '<br/><span style="color:' + point.series.color + '">'u25CF</span>'n' <span onclick="my_function();">Click Me</span> ' + point.series.name + ': ' + point.y;
        });
        return s;
    },
    shared: true
}

我正在做一个拼写错误使用useHtml,但它实际上是useHtml。现在我的问题解决了

试试这个,我将tooltipClick类添加到span

{
    useHtml: true,
    formatter: function () {
        var s = '<b>' + this.x + '</b>';
        $.each(this.points, function (i, point) {
            s += '<br/><span style="color:' + point.series.color + '">'u25CF</span>'n' <span class="tooltipClick">Click Me</span> ' + point.series.name + ': ' + point.y;
        });
        return s;
    },
    shared: true
}

并委托了一个事件处理程序

$(document).on('click','.tooltipClick',function(){
      console.log($(this).parent()); //get the tooltip
      alert('a toolip was clicked')
});