[英]Highcharts - how to show/hide multiple data labels on mouseOver and mouseOut
i want to show data labels only on mousehover. 我想只在mousehover上显示数据标签。 below is the code i tried but its working fine on mouseOver But hiding only one on mouseOut.. jsfiddle is here http://jsfiddle.net/wbmu4sat/5/
下面是我试过的代码,但它在mouseOver上运行正常但是只能在mouseOut上隐藏一个.. jsfiddle在这里 http://jsfiddle.net/wbmu4sat/5/
$(function () {
Highcharts.chart('container', {
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
crosshair: {
color: '#eaeaea'
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
}, {
data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5],
}],
tooltip: {
shared: true
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
align: 'center',
style: {fontSize: '0px' },
states: {
hover: {
enabled: true,
}
}
},
marker: {
radius: 10,
symbol: 'circle',
states: {
hover: {
radius: 20,
symbol: 'circle'
}
}
},
point: {
events: {
mouseOut: function (e) {
this.dataLabel.css({
fontSize: "0px",
});
},
mouseOver: function (e) {
this.dataLabel.css({
fontSize: "10px",
});
}
}
}
}
}
});
});
please find the js fiddle here http://jsfiddle.net/wbmu4sat/5/ 请在这里找到js小提琴http://jsfiddle.net/wbmu4sat/5/
You can use point.update() to enable/disable a point's data label. 您可以使用point.update()来启用/禁用点的数据标签。 On mouseover you can loop through the points and disable data labels for all of them, except the hovered points.
在鼠标悬停时,您可以遍历点并禁用所有这些点的数据标签,但悬停点除外。
events: {
mouseOut: function() {
this.chart.hoverPoints.forEach(p => {
p.update({
dataLabels: {
enabled: false
}
}, false, false);
});
}
},
point: {
events: {
mouseOver: function(e) {
this.series.data.forEach(p => {
p.update({
dataLabels: {
enabled: false
}
}, false, false)
});
this.update({
dataLabels: {
enabled: true
}
});
}
}
}
example: http://jsfiddle.net/vtgbmas7/ 示例: http : //jsfiddle.net/vtgbmas7/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.