我有一个包含多条线的Highchart。 我想禁用某些线条上的工具提示,并在其他线条上保留它。 是否可能? 我知道如何全局禁用工具提示,但不知道如何按系列禁用它。
例如,在标准线图示例中,是否可能在红色和蓝色线上禁用工具提示,但在其他两个线上启用它?
我有一个包含多条线的Highchart。 我想禁用某些线条上的工具提示,并在其他线条上保留它。 是否可能? 我知道如何全局禁用工具提示,但不知道如何按系列禁用它。
例如,在标准线图示例中,是否可能在红色和蓝色线上禁用工具提示,但在其他两个线上启用它?
更新
注意 在这个问题被提出之后,enableMouseTracking: 布尔值
被引入。
旧回答
我刚刚在Tokyo
系列中禁用了高度点。
以下是您的代码:
tooltip: {
formatter: function() {
if(this.series.name == 'Tokyo' && this.y == 26.5 ){
return false ;
// to disable the tooltip at a point return false
}else {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y +'°C';
}
}
}
使用enableMouseTracking
。 这是最好的方法。
每个系列
series: [{
name: 'Serie1',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],
enableMouseTracking: false
}, {
name: 'Serie2',
data: [7.0, 6.9, 9.5, 15.5, 15.2, 15.5, 15.2, 15.5, 11.3, 17.3, 11.9, 9.6]
}]
全局
plotOptions: {
series: {
enableMouseTracking: false
}
}
以上代码仅会为第一个序列显示工具提示。
参考文献: enableMouseTracking
enableMouseTracking
只在 plotOptions
中。plotOptions
中没有 data
属性。 - SovietFrontierseries
(https://api.highcharts.com/highcharts/series.line.enableMouseTracking) 或者 plotOptions
(https://api.highcharts.com/highcharts/plotOptions.series.enableMouseTracking) 中完成它。 - Ricardo Alvaro Lohmann对于股票图表,enableMouseTracking: false 会使得鼠标悬停时线条无法交互。
这里有更好的解决方案:
Highcharts.chart('container', {
series: [{
name: 'John',
type: 'column',
data: [5, 3, 4, 7, 2],
tooltip: {
pointFormatter: function() {
return false
}
}
}, {
name: 'Jane',
type: 'column',
data: [2, 2, 3, 2, 1],
tooltip: {
pointFormatter: function() {
return 'Second <strong>column</strong> series.'
}
}
}, {
name: 'Joe',
type: 'line',
data: [3, 4, 4, 2, 5],
tooltip: {
pointFormatter: function() {
return false
}
}
}]
});
pieFormatter
函数中返回false仍会在悬停时呈现空工具提示。不确定为什么对于此函数返回false仍会呈现工具提示,但需要禁用饼图中的数据点,而且似乎没有任何方法可以实现这一点! - Solomon Closson