eugenursu
Posts: 2
Joined: Mon Jan 24, 2022 10:33 am

enabled = false doesn't hide labels

Hello,
I have a working chart that when clicking on a serie in the legend it switches to show only present and previous year, but when clicking back, the labels of the previous one are still present. (try clicking on 2020 and after click on 2021)

Here is a working jsfiddle: https://jsfiddle.net/eugenursu/zp9a82or/

In a second note, does the Highcharts.addEvent work for clicking on the legend? I can't seem to make it work. Code at the end of the jsfiddle.

Best regards!
magdalena
Posts: 517
Joined: Tue Aug 24, 2021 1:32 pm

Re: enabled = false doesn't hide labels

Hello eugenursu,

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

This is not a bug, but it could be caused by the order of events execution. Due to the option's merging in highcharts, it's not an optional solution to assign properties in the following way :

Code: Select all

series[series.length - 1].options.dataLabels.enabled = true;

You should use the update() function instead.

Code: Select all

              series.update({
                dataLabels: {
                  enabled: true
                }
              })

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

API Reference:
https://api.highcharts.com/class-refere ... ies#update

Let me know if you have any further questions,
Regards!
Magdalena Gut
Developer and Highcharts Support Engineer
eugenursu
Posts: 2
Joined: Mon Jan 24, 2022 10:33 am

Re: enabled = false doesn't hide labels

Good morning,
Thank you for the quick response.

Is there a way to do the load and legendItemClick events after the chart render?

Best regards!
magdalena
Posts: 517
Joined: Tue Aug 24, 2021 1:32 pm

Re: enabled = false doesn't hide labels

Hello,

Could you precise what would you like to achieve?

Here is a great article about how events in Highcharts works:
https://www.highcharts.com/blog/tutoria ... ts-events/

The load event is fired by default after the chart is created and is not triggered by redraw or reflow, but you can trigger it by fireEvent.

Code: Select all

const load = () => Highcharts.fireEvent(chart, 'load');

Demo:
https://jsfiddle.net/BlackLabel/65tngmwq/

When it comes to legendItemClick it toggles the visibly of given series by default, so you can just use the method series.visible() or when you have a custom callback at the legendItemClick you can just invoke it in the different place.

​If you have further inquiries, you may reach out to me at any time,
Regards!
Magdalena Gut
Developer and Highcharts Support Engineer

Return to “Highcharts Usage”