Setting the visibility using the toggleVisibility method in the legendItemHover event leads to legendItemHover being triggered multiple times. Thus, the legendItemLeave method is never called.
If you try to move the cursor slightly the legendItemHover event is fired multiple times and the legendItemLeave event is never called.
The legendItemHover should be fired a single time when the mouse enters the legend and also the legendItemLeave should be fired even if the visibility of the legend is set through the toggleVisibility method.
function onLegendItemHover(e){
e.preventDefault();
console.log("Hover");
let chart = e.sender;
let seriesIndex = e.seriesIndex;
for(let i = 0; i < chart.options.series.length; i++){
if(i !== seriesIndex){
let series = chart.findSeriesByIndex(i);
if (series._options.visible) {
chart.findSeriesByIndex(i).toggleVisibility(false);
}
}
}
}
function onLegendItemLeave(e){
e.preventDefault();
let chart = e.sender;
console.log("Leave");
for(let i = 0; i < chart.options.series.length; i++){
let series = chart.findSeriesByIndex(i);
if (!series._options.visible) {
chart.findSeriesByIndex(i).toggleVisibility(true);
}
}
}
Dojo with workaround - https://dojo.telerik.com/@NeliKondova/EpOYadid