Daniel Ocanto
Posts: 20
Joined: Wed Nov 30, 2022 2:40 pm

Replicate Highchart legend behavior in custom legend.

Hey.

Today I have a question about custom legends, as the title says, I need to replicate the behavior of the native highchart legends, specifically the one they have when hovering over the mouse, which makes that series stand out and the others make them opaque. I already have the code to make them appear and disappear when clicked, but that reaction of highlighting the series that I'm pointing with the mouse from the legend, and hiding the others, I can't replicate it, I think I had seen a series function a long time ago but I don't remember what it is.
I clarify that I do not want to hide the other series when I go over the legend, I just want to make the others opaque and highlight the one I select.

I've created a demo for you to see how the custom legend works. Basically that's the way I make it work, I didn't include the click because it's not necessary, I just want to see how to make the other series hide when hovering over the text as it happens in the default legend.

Demo: https://jsfiddle.net/zsbckq18/24/

I'd like to avoid having to loop through all the series and set setState('inactive') to each one, just so you know, I don't know how many series my chart has. I want to avoid going through all the series, I want to know if there is a function in highchart of the series that already does what I want.

Thank you all.
jakub.j
Posts: 1091
Joined: Tue Jan 24, 2023 11:14 am

Re: Replicate Highchart legend behavior in custom legend.

Thanks for contacting us with your question!

You cannot avoid looping through all the series, that's exactly what Highcharts do under the hood.
I prepared a demo with 2 methods: setHoverState and resetState which allow you to easily recreate exactly the same effect as the default legend has.

Demo: https://jsfiddle.net/BlackLabel/dh0y5218/

I hope you will find it useful
Regards
Jakub
Daniel Ocanto
Posts: 20
Joined: Wed Nov 30, 2022 2:40 pm

Re: Replicate Highchart legend behavior in custom legend.

Thanks for your answer, I'll apply that solution then, I just wanted to know if there was another alternative. By the way, why won't you let me answer more than once? There was an occasion where I was answering a question in another topic and then when I tried to upload a question that I had, it did not let me, it said that it was too early to make a publication.
jakub.j
Posts: 1091
Joined: Tue Jan 24, 2023 11:14 am

Re: Replicate Highchart legend behavior in custom legend.

You're welcome!

As a normal user on our forum, you can't post all the time, it's to prevent spam on the forum. You just need to wait couple of minutes, and you can make another publication.

In case of any further questions, feel free to contact us again.
Best regards
Jakub

Return to “Highcharts Usage”