FGuerreir0PT
Posts: 16
Joined: Fri Mar 25, 2022 3:56 pm

Select an annotation when open a contextMenu

Hello, I am being with some difficulties on select the annotation while I click on right mouse button.

I could manage how to add the contextMenu event but when that event is being triggered the annotation is not being selected (the controlpoints are not showing up), as you can see on the attach file.

Code: Select all

events: {
					contextmenu: function(e) {
						e.preventDefault();
						buildContextMenu( this)
						return false;
					}
The default is to click on left mouse button to select the annotation, in this case I wanted to open a context menu but at the same time to select the annotation as we do the left click. How can i do it?

Thanks
Attachments
annotationResult.png
annotationResult.png (10.72 KiB) Viewed 359 times
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Select an annotation when open a contextMenu

Hi there,

I know what you are trying to achieve but it would be much easier to work on a solution with a live demo.

Please recreate your current right click functionality in an online editor, and we will work on adding the default click event to your existing functionality.

In the meantime, you can try to do it yourself. You can find the click event for the annotation in annotation.options.events.click, as an argument this function expects a this keyword which will point to the annotation that is calling the click method.

Let us know once you recreate the demo,
Regards!
Kamil Musiałowski
Highcharts Developer
FGuerreir0PT
Posts: 16
Joined: Fri Mar 25, 2022 3:56 pm

Re: Select an annotation when open a contextMenu

Hello Kamil, yes I was taking care of the example to be shared:
So here it is:
https://codepen.io/fguerreir0/pen/zYPjMpP?editors=1111

Meanwhile will try to do it as you explained
Thanks
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Select an annotation when open a contextMenu

Hi there,

Thank you for the demo - it helped a lot!

I have prepared a working solution for you, please check it out below.
I am calling the annotation click method and manually binding the this keyword by using JS call. In my previous post, I said that it expects the this keyword as an argument. Sorry, that might have confused you. I meant to call the function with the this keyword.

DEMO: https://codepen.io/kamil-musialowski/pe ... itors=0011

Let me know if that is what you were looking for,
Best regards!
Kamil Musiałowski
Highcharts Developer
FGuerreir0PT
Posts: 16
Joined: Fri Mar 25, 2022 3:56 pm

Re: Select an annotation when open a contextMenu

Thank you Kamil, still struggling with it.
On your example doesn't seem to click on the drawed line. At least the control points are not showing up
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Select an annotation when open a contextMenu

Hello FGuerreir0PT,

Can you check out this demo?
Demo: https://jsfiddle.net/BlackLabel/a5Ltq67o/

Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
FGuerreir0PT
Posts: 16
Joined: Fri Mar 25, 2022 3:56 pm

Re: Select an annotation when open a contextMenu

Hello Michal, yes it worked, thanks!
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Select an annotation when open a contextMenu

That's great to hear! In case of any further questions, feel free to contact us again.

Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/

Return to “Highcharts Usage”