Page 1 of 1

Custom draw on ViewXY

Posted: Thu Sep 03, 2020 3:48 pm
by AndyFraser
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

Re: Custom draw on ViewXY

Posted: Fri Sep 04, 2020 12:36 pm
by Arction_LasseP
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

Re: Custom draw on ViewXY

Posted: Fri Sep 04, 2020 4:22 pm
by AndyFraser
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

Re: Custom draw on ViewXY

Posted: Mon Sep 07, 2020 6:16 am
by Arction_LasseP
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

Re: Custom draw on ViewXY

Posted: Wed Sep 09, 2020 8:38 am
by AndyFraser
Lasse,

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

Andy