highcharts - Highcharts - 如何在点击时只显示两个系列
问题描述
我发现这个例子有一半可以满足我的需要。我需要它来展示两个系列,而不仅仅是一个。
events: {
show: function () {
var chart = this.chart,
series = chart.series,
i = series.length,
otherSeries;
while (i--) {
otherSeries = series[i];
if (otherSeries != this && otherSeries.visible) {
otherSeries.hide();
}
}
},
legendItemClick: function() {
if(this.visible){
return false;
}
}
}
例如:我点击系列 1,我看到系列 1 和 2。我点击系列 3,我看到系列 3 和 4。系列 2 和 4 将隐藏在图例中。是否可以?
解决方案
您可以链接具有相同可见性的系列并在legendItemClick
事件中隐藏其他系列:
plotOptions: {
series: {
events: {
legendItemClick: function() {
if (this.visible) {
return false;
}
this.chart.series.forEach(function(s) {
if (s !== this && s !== this.linkedSeries[0]) {
s.hide();
}
}, this);
}
}
}
},
series: [{
data: [...],
id: 'first'
}, {
data: [...],
linkedTo: 'first'
}, {
data: [...],
visible: false,
id: 'third'
}, {
data: [...],
linkedTo: 'third'
}]
现场演示:http: //jsfiddle.net/BlackLabel/s6x37azb/
API 参考: https ://api.highcharts.com/highcharts/series.line.linkedTo
推荐阅读
- reactjs - 如何在数组中添加对象
- angular - ngbTooltip 和 ngb 分页不起作用
- python - `__dict__` 何时重新初始化?
- c++ - 如何使用 libpqxx 获取 postgres sqlerrorcode?
- json - 如何遍历下面给出的json数据我得到错误
- dart - 如何在颤振中重用同一个小部件的内容?
- javascript - 如何拆分数组以分隔 JavaScript 中的后续相似项
- c# - 如何解决通过套接字接收数据的问题?
- sql - 无法在 GrapeJS 编辑器角度节点框架中呈现 CSS 数据
- javascript - 在我的快速应用程序中找不到 javascript 文件