Highcharts工具提示中的可点击链接

Clickable link in tooltip of Highcharts

本文关键字:链接 工具提示 Highcharts      更新时间:2023-09-26

我有一个包含数据列表的工具提示。我希望每个数据都是一个链接,重定向到该特定数据的页面。Highcharts工具提示的问题是它会随x轴变化。一旦x轴发生变化,工具提示就会变为x轴上的相应组件。所以,如果我得到我的工具提示与链接工作,只要我移动到点击链接,工具提示改变。为了解决这个问题,我想出了一种方法来修复工具提示,只要你点击工具提示。这里是代码。

plotOptions: {
        series: {
            cursor: 'pointer',
            point: {
                events: {
                    click: function() {
                        if (cloneToolTip)
                        {
                            chart.container.firstChild.removeChild(cloneToolTip);
                        }
                        cloneToolTip = this.series.chart.tooltip.label.element.cloneNode(true);
                        chart.container.firstChild.appendChild(cloneToolTip);
                    }
                }
            }
        }
    },

但即使这样,我需要使工具提示中的链接是可点击的。我在stackoverflow上看到了一些线程,他们已经做到了,但它也不工作。它将它们显示为链接,但它们是不可点击的。在这里张贴一个工作示例。

JSFiddle工作示例

如有任何帮助,不胜感激。

编辑1:-这些是我所有的级数。可能是工具提示被隐藏了,因为一些其他的图表。

series: [{
        type: 'column',
        name: 'Success',
        color: '#7deda2',
        yAxis: 1,
        tooltip: {
            pointFormatter: function(){
              return "Success: " + this.y + "%" + "<br />" + "Success docs: " + toolTipSuccess[this.series.data.indexOf( this )] + "<br />";
            }
        },
        data: [{{barSuccess}}]
    }, 
    {
      type: 'scatter',
      name: 'Incidents',
      yAxis: 1,
      data: scatterData,
      color: '#FFAE19',
      tooltip: {
            pointFormatter: function() {
              var string = '';
              Highcharts.each(toolTip[this.series.data.indexOf(this)], function(p) {
                string += '<a href="http://www.google.com">' + p + '</a><br>'
              });
              return string + "<br />";
            }
          },
    },
    {
        type: 'spline',
        name: 'Failure',
        tooltip: {
            pointFormatter: function(){
              return "Failure: " + this.y + "%" + "<br />" + "Failure docs: " + toolTipFailure[this.series.data.indexOf( this )] + "<br />";
            }
        },
        data: [{{barFailure}}],
        marker: {
            lineWidth: 3,
            lineColor: Highcharts.getOptions().colors[8],
            fillColor: 'red'
        }
    },
    {{#if lu}}
       {
        type: 'spline',
        name: 'Unknown',
        tooltip: {
            pointFormatter: function(){
              return "Unknown: " + this.y + "%" + "<br />" + "Unknown docs: " + toolTipUnknown[this.series.data.indexOf( this )] + "<br />";
            }
        },
        data: [{{barUnknown}}],
        marker: {
            lineWidth: 3,
            lineColor: 'blue',
            fillColor: '#87CEFA'
        }
    }
    {{/if}}

工具提示的useHTML属性应该在全局工具提示属性中定义-但对于<a>是不够的。更改pointerEvents属性是必要的-您可以在这里看到问题:https://github.com/highcharts/highcharts/issues/5722

tooltip: {
  useHTML: true,
  style: {
    pointerEvents: 'auto'
  }
},

示例:http://jsfiddle.net/SeCAB/216/