Bhargavi
Posts: 25
Joined: Mon May 29, 2023 1:00 pm

Highcharts x-axis click event

Hi,

How can I add clcik event to the x-axis and get the x-axis value.
https://jsfiddle.net/ov0Lkpa8/
andrzej.b
Site Moderator
Posts: 307
Joined: Mon Jul 15, 2024 12:34 pm

Re: Highcharts x-axis click event

Hi,

Thanks for contacting us with your question!

It is possible, please see the sample implementation here: https://jsfiddle.net/BlackLabel/h89opt42/

Let me know if that is what you were looking for!

Best regards,
Andrzej
Highcharts Developer
Bhargavi
Posts: 25
Joined: Mon May 29, 2023 1:00 pm

Re: Highcharts x-axis click event

Hi Andrzje,

Thank you for your response.
I don't see the console value printing, could you please check it once and confirm.
I have two scenarios
1. On click on the line I need to catch the value
2. On click on the x-axis i.e years below the chart I need to catch the year which I clicked

Thank you,
Bhargavi
andrzej.b
Site Moderator
Posts: 307
Joined: Mon Jul 15, 2024 12:34 pm

Re: Highcharts x-axis click event

Hi,

Ok, given more precise requirements I have prepared for you implementation of these two click event listeners: https://jsfiddle.net/BlackLabel/7vhr019j/

Let me know if that is what you were looking for!

Best regards,
Andrzej
Highcharts Developer
Bhargavi
Posts: 25
Joined: Mon May 29, 2023 1:00 pm

Re: Highcharts x-axis click event

Hi Andrzje,

Thank you for your response.

I see the second point is working as expected but the first point seems like not working, can you please take a look on this?

1. On click on the line I need to catch the value

Thank you,
Bhargavi
andrzej.b
Site Moderator
Posts: 307
Joined: Mon Jul 15, 2024 12:34 pm

Re: Highcharts x-axis click event

Hi,

I checked it again, and it works, console log fires when you click within the +-3px range (up-bottom) on the xAxis line. You can adjust the range to your needs to make it easier for testing at line 14; just mind the possible overlap with the series lines: https://jsfiddle.net/BlackLabel/h6sey54a/

Feel free to reach out if you have any further questions.

Best regards,
Andrzej
Highcharts Developer
Bhargavi
Posts: 25
Joined: Mon May 29, 2023 1:00 pm

Re: Highcharts x-axis click event

Hi Andrzej,

I have observed this is only working when y-axis value is 0 and is not working on above y-axis values, I also tested the above example, I don't see the console printing.

Thank you,
Bhargavi
andrzej.b
Site Moderator
Posts: 307
Joined: Mon Jul 15, 2024 12:34 pm

Re: Highcharts x-axis click event

Hi,

Once again, I've retested the setup, and it works, also above the xAxis line. If the current range is not sufficient, then just please increase the range.

In case of any other questions, feel free to contact us anytime.

Kind regards,
Andrzej
Highcharts Developer
Bhargavi
Posts: 25
Joined: Mon May 29, 2023 1:00 pm

Re: Highcharts x-axis click event

Hi Andrzej,

While I am trying to call a function this.updateChart() inside chart options, I am getting the error, couldyou please check this once.
https://jsfiddle.net/knxaq3sv/

Thank you,
Bhargavi
Bhargavi
Posts: 25
Joined: Mon May 29, 2023 1:00 pm

Re: Highcharts x-axis click event

Bhargavi wrote: Mon Nov 11, 2024 6:36 am Hi Andrzej,

While I am trying to call a function this.updateChart() inside chart options, I am getting the error, couldyou please check this once. Also When I try to get the series data onclick x-axis it is giving me the undefined at line no 57
https://jsfiddle.net/fwc2avko/2/
Thank you,
Bhargavi
andrzej.b
Site Moderator
Posts: 307
Joined: Mon Jul 15, 2024 12:34 pm

Re: Highcharts x-axis click event

Hi,

There are some issues with the syntax of your code (missing proper function definition and scope issues), I have fixed them for you here: https://jsfiddle.net/BlackLabel/rhx1w4p3/

Best,
Andrzej
Highcharts Developer

Return to “Highcharts Stock”