[英]HighCharts line chart - How to prevent the deselection of the last legend item?
Is there a way to prevent the hiding of the last legend item that's being deselected in a line chart? 有没有办法防止隐藏折线图中取消选择的最后一个图例项目?
I've achieved it on a column/pie charts using the legendItemClick event: 我已经使用legendItemClick事件在柱形图/饼图上实现了它:
legendItemClick: function (e) {
var self = this;
var hiddenSeries = function () {
var counter = 0;
$.each(self.series.points, function (i, v) {
if (!v.visible) {
counter++;
}
});
return counter;
}
if (self.series.points.length - 1 == hiddenSeries() && self.visible) {
return false;
} else {
return true;
}
}
and it works pretty well as you can see on the following fiddle , however, it doesn't work with line charts since the 'this' object doesn't contain the 'series.points' property. 而且您可以在下面的小提琴中看到它的效果,但是它不适用于折线图,因为“ this”对象不包含“ series.points”属性。
You can refer to the chart variable to get at the series info. 您可以参考图表变量以获取系列信息。 I did it like this: 我这样做是这样的:
legendItemClick: function (e) {
var visibleSeries = function () {
var counter = 0;
$.each(chart.series, function (i, v) {
if (v.visible) {
counter++;
}
});
return counter;
}
if (visibleSeries() <= 1 && this.visible) {
return false;
} else {
return true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.