Page 1 of 1

How to move or drag and drop LineCollection in Chart?

Posted: Wed May 13, 2020 11:41 am
by MirroZV
Hello guys.

We have a quite simple chart with X and Y axis. We are using points to show chart.
We have a "tracker", what is vertical line in chart to show selected point by user.
We have a request to do this "tracker" moveable (or drag and drop), that user can select point on chart by "tracker".
"Tracker" is class which inherited from FrameworkElement. As visualization we are using LineCollection class.

My quections are:
1. is it possible to implement something for "tracker" to by moveable or to use drag and drop function?
2. if yes - can you please help me how?
2. if no - is it possible somehow else or it is just impossible?

Thanks for answers.
tracker.jpg
tracker.jpg (94.08 KiB) Viewed 13529 times

Re: How to move or drag and drop LineCollection in Chart?

Posted: Thu May 14, 2020 9:03 am
by Arction_LasseP
Hello,

LightningChart has LineSeriesCursor which is very similar to this "tracker".

LineSeriesCursor is a vertical line which can be dragged by mouse and can be set to snap to the nearest data point.

Code: Select all

            // Adding a line series cursor in code.
            LineSeriesCursor cursor = new LineSeriesCursor(_chart.ViewXY, axisX);
            cursor.ValueAtXAxis = 5;    // Assign cursor to x-position 5.
            cursor.SnapToPoints = true; // Cursor will snap to nearest point.
            cursor.MoveByMouse = true; // Can move the cursor by dragging it, is enabled by default
            _chart.ViewXY.LineSeriesCursors.Add(cursor);
You can also check our PointLine demo example too see how cursor works
Cursor.PNG
Cursor.PNG (76.32 KiB) Viewed 13526 times
Hope this helps.
Best regards,
Lasse

Re: How to move or drag and drop LineCollection in Chart?

Posted: Fri May 15, 2020 1:29 pm
by MirroZV
Hello.

Thanks for answer.
I already tried it and my cursor cannot snap to points.

Can you please help me what I am doing wrong?

Thanks
snaping.PNG
snaping.PNG (10.69 KiB) Viewed 13516 times

Re: How to move or drag and drop LineCollection in Chart?

Posted: Mon May 18, 2020 10:08 am
by Arction_LasseP
Hello,

One reason why LineSeriesCursor is not snapping to points could be that you are using LineCollection instead of PointLineSeries, apologies for not spotting this earlier. LineCollection cannot be tracked by the Cursor, only series implementing ITrackable interface can (SampleDataSeries, PointLineSeries, AreaSeries, HighLowSeries).

However, according to the images you have, you could very well use PointLineSeries instead. LineCollection is efficient in rendering of thousands of distinct line segments, in contrast to PointLineSeries, FreeformPointLineSeries or SampleDataSeries which are more efficient in rendering continuous polylines of millions of points. Otherwise LineCollection does not offer any benefits compared to PointLineSeries.

Therefore the easiest option would be to switch using PointLineSeries.

If this is not an option, then you have to implement this snapping manually. It is possible with some mouse events and tracking the nearest data point of the mouse cursor.

Best regards,
Lasse