highcharts为单个点自定义工具提示

highcharts为单个点自定义工具提示,highcharts,customization,tooltip,Highcharts,Customization,Tooltip,我想自定义特定系列中最后一个点的工具提示,将此系列和其他系列中的其他点保留为默认工具提示格式。基本上,我正在寻找类似于此配置的东西。提前感谢您的帮助 series: [{ tooltip: { // ?? tooltip does not work inside series formatter: function() { if (lastPoint in the series) { // ?

我想自定义特定系列中最后一个点的工具提示,将此系列和其他系列中的其他点保留为默认工具提示格式。基本上,我正在寻找类似于此配置的东西。提前感谢您的帮助

series: [{
            tooltip: {    // ?? tooltip does not work inside series
                formatter: function() {
                    if (lastPoint in the series) {  // ?? how to determine if lastPoint
                        return '<b>Final result is </b> ' + this.y;
                    }
                    // ?? return default format if it is not the last point in the series
                }
            },            
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6]        
        }, {
            data: [194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2]        
        }]
系列:[{
工具提示:{//?工具提示在系列中不起作用
格式化程序:函数(){
if(系列中的lastPoint){/?,如何确定lastPoint
返回“最终结果为”+此.y;
}
//?如果不是系列中的最后一点,则返回默认格式
}
},            
数据:[29.9,71.5106.4129.2144.0176.0135.6]
}, {
数据:[194.1,95.6,54.4,29.9,71.5,106.4,129.2]
}]

格式化程序函数在为系列定义时似乎不起作用。您可以使用this.series.name检查您所处的系列,然后使用this.series.xData.length-1==this.point.x检查您是否处于最终点。但是,命名您想要定位的点并在formatter函数中检查它会更容易。要查看所有格式化程序数据,请选中此处

$(“#容器”)。高图({
xAxis:{
类别:[一月、二月、三月、四月、五月、六月、七月]
},
工具提示:{
格式化程序:函数(){
var工具提示;
如果(this.key=='last'){
工具提示='最终结果为'+this.y;
}
否则{
工具提示=“”+this.series.name+”:“+this.y+”
”; } 返回工具提示; } }, 系列:[{ 数据:[29.9,71.5,106.4,129.2,144.0,176.0,{y:135.6,name:'last'}] }, { 数据:[194.1,95.6,54.4,29.9,71.5,106.4,129.2] }] });
$('#container').highcharts({   
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul']
    },
    tooltip : {
        formatter: function() {
            var tooltip;
            if (this.key == 'last') {
                tooltip = '<b>Final result is </b> ' + this.y;
            }
            else {
                tooltip =  '<span style="color:' + this.series.color + '">' + this.series.name + '</span>: <b>' + this.y + '</b><br/>';
            }
            return tooltip;
        }
    },   
    series: [{
                data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, {y:135.6, name: 'last'}]

    },
    {
        data: [194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2]
    }]

});