如何从共享工具提示格式化程序Highcharts中获取突出显示的点

时间:2015-03-09 07:24:04

标签: javascript jquery highcharts

我使用共享工具提示(http://api.highcharts.com/highcharts#tooltip.formatter),以便我可以遍历this.points以将所有y值放入工具提示中:

if (this.points) {
    $.each(this.points, function(i, point) {
        console.log(i, point);
        s += ......//use all the points to construct common tooltip,which has been done
    });

//However, after shared tooltip, how can I get the highlighted point? I use `this` but it always point to the same one.

s += //need To know The highlighted point somewhere to construct the tooltip as well

}

在选择之前,系列将如下:

before hover

工具提示格式化程序中是否有任何方法可以知道选择了哪个点/索引?在下面的屏幕截图中,选择了蓝色的一个,我需要蓝点对象数据。

blue line is selected

2 个答案:

答案 0 :(得分:4)

请尝试使用默认工具提示,而不是使用共享工具提示:http://jsfiddle.net/2v0ya6d5/1/

代码:

    tooltip: {
        formatter: function () { 
            var series = this.point.series.chart.series, // get all series 
                index = this.point.series.xData.indexOf(this.point.x), // get index
                str = '';

            // default tooltip
            $.each(series, function(i, s) { 
                str += 'The value for <b>' + s.data[index].category +
                '</b> is <b>' + s.data[index].y + '</b><br>'
            });

            // "this" refers to the selected point:
            str+= 'Selected point? x: ' + this.x + ' y: ' + this.y;

            return str;
        }
    },

答案 1 :(得分:0)

你做错了。您不需要为此目的循环。如果您只需要一个点/数据对象,则可以使用this

循环points用于检查垂直对齐的每个点(相同x)。

formatter文档的链接上,您有另一个链接:

http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/tooltip/formatter-simple/

你可以看到这个例子,我认为这就是你要做的事情。

相关问题