Forgive me if this has been asked before but I am evaluating LightningChart for WinForms and would like the user to click on the chart and have a custom cursor shown. The idea is that the user can place two cursors and some statistics about the range of data between the two cursors would be shown on a modeless dialogue box. I can't see in the documentation any mention of custom draw on the chart surface.
Best Regards
Andy
Custom draw on ViewXY
Moderator: Queue Moderators
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Custom draw on ViewXY
Hello Andy,
This can be done for example by subscribing to mouse events, and create an object, in this case a cursor, inside the event. For instance, the following adds a LineSeriesCursor to the mouse click position:
Note that you get the mouse click position via e.X as screen coordinates, not axis values. This is why we are using CoordToValue method to convert the screen coordinate to respective X-axis value. The same can be done to Y-value as well if that is needed.
You can use cursor.ValueAtXAxis also to measure the distance between two cursors.
Hope this is helpful.
Best regards,
Lasse
This can be done for example by subscribing to mouse events, and create an object, in this case a cursor, inside the event. For instance, the following adds a LineSeriesCursor to the mouse click position:
Code: Select all
_chart.MouseClick += _chart_MouseClick;
private void _chart_MouseClick(object sender, MouseEventArgs e)
{
LineSeriesCursor cursor = new LineSeriesCursor(_chart.ViewXY, _chart.ViewXY.XAxes[0]);
double xPos = 0;
_chart.ViewXY.XAxes[0].CoordToValue(e.X, out xPos, true, true);
cursor.ValueAtXAxis = xPos;
_chart.ViewXY.LineSeriesCursors.Add(cursor);
}
You can use cursor.ValueAtXAxis also to measure the distance between two cursors.
Hope this is helpful.
Best regards,
Lasse
-
- Posts: 3
- Joined: Thu Sep 03, 2020 3:43 pm
Re: Custom draw on ViewXY
Lasse,
That works great
Is it possible to change the colour of the cursor lines as I would like for them to work in pairs and it would allow the user to easily identify the paired cursors?
Andy
That works great
Is it possible to change the colour of the cursor lines as I would like for them to work in pairs and it would allow the user to easily identify the paired cursors?
Andy
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Custom draw on ViewXY
Hello Andy,
You can change the appearance of the cursor via LineStyle.
LineStyle includes also other settings besides color, for instance line width and pattern (dash, dot etc.).
Best regards,
Lasse
You can change the appearance of the cursor via LineStyle.
Code: Select all
cursor.LineStyle.Color = Color.Blue;
Best regards,
Lasse
-
- Posts: 3
- Joined: Thu Sep 03, 2020 3:43 pm
Re: Custom draw on ViewXY
Lasse,
Thanks for that - I should have been able to figure that out for myself
Andy
Thanks for that - I should have been able to figure that out for myself
Andy