evoker
Posts: 40
Joined: Tue Dec 01, 2020 1:01 pm

Programmatically clicking a bar "point"

Good day!

I am trying to trigger the click event for a stacked bar chart point, but the event contains no point property which is needed for what I'm trying to achieve.

With your great help from this forum, I currently have this chart: https://codepen.io/ev0k3r/pen/eYMYJJo

When I click the "click!" button, I get the error: Uncaught TypeError: Cannot read properties of undefined (reading 'series')

The event doesn't contain some of the properties contained in the click event object when it's not triggered directly from the chart itself. Is there a workaround to this?
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: Programmatically clicking a bar "point"

Hello evoker!

I suggest you change your logic a little bit and move the code responsible for showing multiple tooltips to a separate function, which will be called in point click event and also on the button click event. Thanks to that, your logic won't base on JavaScript events, which in your demo case are different. These events contain other properties/pieces of information, so it's better to get proper data from the event and then call a function. I also recommend to add click listener to button in chart load event, because you get access to the chart without getting it by hoisted variable, as in your demo from the first post.

Demo: https://codepen.io/hubertkozik/pen/mdxejWG

Let me know if that fits your requirement.
Kind regards!
Hubert Kozik
Highcharts Developer
evoker
Posts: 40
Joined: Tue Dec 01, 2020 1:01 pm

Re: Programmatically clicking a bar "point"

Excellent, thanks for the idea! I moved some stuff around and got the desired result.
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: Programmatically clicking a bar "point"

You're welcome! In case of any further questions, feel free to contact us again.
Hubert Kozik
Highcharts Developer

Return to “Highcharts Usage”