Custom draw on ViewXY

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
AndyFraser
Posts: 3
Joined: Thu Sep 03, 2020 3:43 pm

Custom draw on ViewXY

Post by AndyFraser » Thu Sep 03, 2020 3:48 pm

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

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

Re: Custom draw on ViewXY

Post by Arction_LasseP » Fri Sep 04, 2020 12:36 pm

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:

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);
}
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

AndyFraser
Posts: 3
Joined: Thu Sep 03, 2020 3:43 pm

Re: Custom draw on ViewXY

Post by AndyFraser » Fri Sep 04, 2020 4:22 pm

Lasse,

That works great :D
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

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

Re: Custom draw on ViewXY

Post by Arction_LasseP » Mon Sep 07, 2020 6:16 am

Hello Andy,

You can change the appearance of the cursor via LineStyle.

Code: Select all

cursor.LineStyle.Color = Color.Blue;
LineStyle includes also other settings besides color, for instance line width and pattern (dash, dot etc.).

Best regards,
Lasse

AndyFraser
Posts: 3
Joined: Thu Sep 03, 2020 3:43 pm

Re: Custom draw on ViewXY

Post by AndyFraser » Wed Sep 09, 2020 8:38 am

Lasse,

Thanks for that - I should have been able to figure that out for myself :oops:

Andy

Post Reply