How to move or drag and drop LineCollection in Chart?

Need help in implementing some specific function to your LightningChart Ultimate powered application? Post a question and get code snippets from other LightningChart Ultimate community members.

Moderator: Queue Moderators

Post Reply
MirroZV
Posts: 45
Joined: Wed May 13, 2020 10:41 am

How to move or drag and drop LineCollection in Chart?

Post by MirroZV » Wed May 13, 2020 11:41 am

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 12932 times

Arction_LasseP
Posts: 141
Joined: Wed Mar 27, 2019 1:05 pm

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

Post by Arction_LasseP » Thu May 14, 2020 9:03 am

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 12929 times
Hope this helps.
Best regards,
Lasse

MirroZV
Posts: 45
Joined: Wed May 13, 2020 10:41 am

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

Post by MirroZV » Fri May 15, 2020 1:29 pm

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 12919 times

Arction_LasseP
Posts: 141
Joined: Wed Mar 27, 2019 1:05 pm

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

Post by Arction_LasseP » Mon May 18, 2020 10:08 am

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

Post Reply