Javascript Highcharts共享工具提示的工具提示格式

Javascript Highcharts共享工具提示的工具提示格式,javascript,highcharts,Javascript,Highcharts,例如,如果我有一个包含三个系列的图表,并且工具提示设置为“共享”,我希望对工具提示的格式有更多的控制。目前,我使用formatter:somefunction()并创建自己的html以在显示的工具提示中使用。现在这很好,但现在我想知道格式化程序函数何时触发我结束的序列,以便在工具提示中的三个序列中,我可以相应地格式化显示的文本 共享工具提示: 标题标签 Series 1 Series 2 (If I am hovering over this item I want to bold it

例如,如果我有一个包含三个系列的图表,并且工具提示设置为“共享”,我希望对工具提示的格式有更多的控制。目前,我使用formatter:somefunction()并创建自己的html以在显示的工具提示中使用。现在这很好,但现在我想知道格式化程序函数何时触发我结束的序列,以便在工具提示中的三个序列中,我可以相应地格式化显示的文本

共享工具提示:

标题标签

  Series 1
  Series 2 (If I am hovering over this item I want to bold it in the formatter function)
  Series 3

共享工具提示中没有此类信息-只需将空白悬停在图表上(系列中没有),即可显示,请参见:

可能对您有效的解决方案是禁用共享工具提示,并使用以下方法从其他系列获取值:

var xIndex = this.series.xData.indexOf(this.x),
    allSeries = this.series.chart.series;
现在循环所有系列,并使用
allSeries[index].yData[xIndex]
从每个系列中获取值


当然,如果
this.series.index
(或
this.series.options.index
)与上面的
index
相同,则生成粗体文本。

感谢您的指导。我在这里发布完整的代码来实现这一点。希望它能帮助其他人。

// Header for tooltip.
// This row consists of bold text, with the text being the xAxis Label 
// that the Series falls in followed by the Chart Title.
var toolTip = '<b>' + this.x + ' ' + chartTitle + '</b><br/>';

// Get the current index in the Series you are hovering over.
var xIndex = this.series.xData.indexOf(this.point.x);

// Get all the Series represented in the Chart.
var allSeries = this.series.chart.series;

// Loop over each Series.
for (var index = 0; index < allSeries.length; index++) {
    // Get the value from each Series.
    var yDataValue = allSeries[index].yData[xIndex];

    // Check if this is the same as index and if it is then you are 
    // hovering over the point that needs the text in the formatted tooltip in bold for that Series.
    if (this.series.index === index || this.series.options.index === index) {
        //
        // Generate Bold Text here.
        //

        toolTip = toolTip + '<b>' + allSeries[index].name + ': ' + yDataValue + '</b>';
    }
    else {
        toolTip = toolTip + allSeries[index].name + ': ' + yDataValue;
    }
}
//工具提示的标题。
//此行由粗体文本组成,文本为xAxis标签
//该系列出现在图表标题之后。
变量工具提示=“”+this.x+“”+chartTitle+”
; //获取您悬停的系列中的当前索引。 var xIndex=this.series.xData.indexOf(this.point.x); //获取图表中表示的所有系列。 var allSeries=this.series.chart.series; //在每个系列上循环。 对于(var index=0;index