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

add a segment line clone

Hey there, need some help to find the issue I am doing.
So I am implementing a context menu with some options, one of them is to Clone the selected Segment Line.

I could manage how to clone but the click event above it is not identifying it as a segment line, so it doesn't allow me to edit or to have control points.

I am doing this when I click on Clone:

Code: Select all

			var newAnnotation = {
				shapes: [{
					type: 'path',
					strokeWidth: 1,
					points: [{
						x: annotationClicked.points[0].x,
						y: annotationClicked.points[0].y - 0.00001,
						xAxis: 0,
						yAxis: 0
					}, {
						x: annotationClicked.points[1].x,
						y: annotationClicked.points[1].y - 0.00001,
						xAxis: 0,
						yAxis: 0
					}]
				}]
			}
It creates a new line but when I click on it I don't have control points and the popup indentifies it as undefined, as you can see on the attached image.
Best regards!
Attachments
Sem Título.png
Sem Título.png (7.9 KiB) Viewed 294 times
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: add a segment line clone

Hello,

You are very close to the solution, but there is a difference between these two lines.

When you draw a line on the chart using stockTools GUI it is a crookedLine. In your clone, you are creating a simple path that has a bit different options built in.

To fix that, simply change the type on the annotation that you are adding to your chart as a clone to crookedLine.
Also, you can add them through the chart.addAnnotation method.
To change the title that's displayed in the edit menu, simply set the langKey property to the desired string.

Take a look at the demo and API Reference below with those features implemented.

DEMO: https://jsfiddle.net/BlackLabel/n3dwjr0a/
API Reference: https://api.highcharts.com/class-refere ... Annotation
https://api.highcharts.com/highstock/an ... apeOptions

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

Re: add a segment line clone

Thank you kamil, I tried to change as you suggested but still have some issues.
The issue comes from the modules imported, v10.2.

What you suggests to do?
Attachments
error2.png
error2.png (24.96 KiB) Viewed 265 times
error1.png
error1.png (31.6 KiB) Viewed 265 times
FGuerreir0PT
Posts: 16
Joined: Fri Mar 25, 2022 3:56 pm

Re: add a segment line clone

Found the issue, I was passing the type and the properties of the line inside of shapes object and then I was adding it as a new annotation.

Thanks Kamil!
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: add a segment line clone

Yes, that might be a bit confusing at first, but I'm glad that you have managed to fix it yourself.

In case of any other questions, feel free to ask!
Have a good day
Kamil Musiałowski
Highcharts Developer

Return to “Highcharts Usage”