8

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

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]        
        }]
4

1 回答 1

16

为系列定义格式化程序功能时,它似乎不起作用。您可以使用 this.series.name 检查您所在的系列,然后您可以使用 this.series.xData.length - 1 == this.point.x 检查您是否在最后一点。但是,命名您想要定位的点并在格式化程序函数中检查它会更容易。http://jsfiddle.net/Swsbb/。要查看所有格式化程序数据,请在此处查看http://api.highcharts.com/highcharts#tooltip.formatter

$('#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]
    }]

}); 
于 2013-08-07T23:24:51.200 回答