highcharts为单个点定制工具提示 [英] highcharts customize tooltip for a single point
问题描述
我想自定义特定系列中最后一个点的工具提示,并使用默认工具提示格式保留该系列和其他系列中的其他点.基本上,我正在寻找与此配置类似的东西.预先感谢您的帮助!
I want to customize the tooltip of the last point in a specific series, leave other points in this series, and other series, with default tooltip format. Basically, I am looking for something similar to this config. Thanks in advance for your help!
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]
}]
推荐答案
为系列定义格式化程序功能后,它似乎不起作用.您可以使用this.series.name来检查属于哪个系列,然后可以使用this.series.xData.length-1 == this.point.x来检查是否位于终点.但是,在格式化程序函数中命名要定位的点并进行检查会更容易. http://jsfiddle.net/Swsbb/.要查看所有格式化程序数据,请在此处 http://api.highcharts.com/highcharts#tooltip.格式化程序.
The formatter function doesn't seem to work when it's defined for a series. You can check which series you are in by using this.series.name and then you can check if you are on the final point using this.series.xData.length - 1 == this.point.x. But, it would be easier to name the point that you want to target and check for that in the formatter function. http://jsfiddle.net/Swsbb/. To see all the formatter data, check here 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]
}]
});
这篇关于highcharts为单个点定制工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!