adcextra
Posts: 2
Joined: Thu Feb 18, 2021 7:07 pm

Event Listener disappear for plotline labels after chart zoom in

Hi! I am working on a project with Highcharts and met some issues when adding event listener for plotlines' labels elements.

Demo URL: https://jsfiddle.net/1xzgmhps/7/

What I want to do is to add a click event listener for the button on a plotlinel's label. It works perfectly when chart just inits. However, if I zoom in the chart to the area, where the plotline is not in, after I reset zoom, the event listener for the button won't work anymore. I am wondering if there're some solutions to this problem.

Thanks!
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Event Listener disappear for plotline labels after chart zoom in

Hi,
Welcome to our forum and thanks for contacting us with your question!

Could you explain more preciously what's wrong?

I can't see any problem with your chart, I made a demo with a show and hide plot line for the better understanding.
https://jsfiddle.net/BlackLabel/g0tyo139/

Let me know if that was what you were looking for.
Best regards.
Sebastian Hajdus
Highcharts Developer
adcextra
Posts: 2
Joined: Thu Feb 18, 2021 7:07 pm

Re: Event Listener disappear for plotline labels after chart zoom in

Hi,

Based on your demo, I click on the button and the plotline can hide/show, right?
Then I zoom to an area where the plotline is not in, let's say 5-6 on the xaxis. And after that I reset the zoom and click the button on the line again, the button doesn't work any more.
dominik.c
Posts: 2081
Joined: Fri Aug 07, 2020 7:07 am

Re: Event Listener disappear for plotline labels after chart zoom in

Hi adcextra!

It happens because you've added event listener only once after the chart got loaded. When you zoom to the range, where we don't have the button, the button simply disappears (in console you can see that the label is undefined), so after each redraw we need to add a new event listener.

API references: https://api.highcharts.com/highcharts/c ... nts.redraw

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

I hope that I made it clear to you. Feel free to ask any further questions!
Best regards!
Dominik Chudy
Highcharts Developer

Return to “Highcharts Usage”