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.
How to move or drag and drop LineCollection in Chart?
Moderator: Queue Moderators
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: How to move or drag and drop LineCollection in Chart?
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.
You can also check our PointLine demo example too see how cursor works
Hope this helps.
Best regards,
Lasse
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);
Hope this helps.
Best regards,
Lasse
Re: How to move or drag and drop LineCollection in Chart?
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
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
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: How to move or drag and drop LineCollection in Chart?
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
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