Limit the display range on ViewXY

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

Posts: 1
Joined: Tue Jun 16, 2020 7:18 am

Limit the display range on ViewXY

Post by AlexNorton » Tue Jun 16, 2020 8:22 am


I need to restrict the x-axis to display only certain range, e.g. 0 - 1000. If the min of the chart is currently displayed at 0 - 50, there are 2 possible responses depending on the type of action:
1) if the action is panning to the left, the range, min(0) and max(50) should be maintained.
2) if the action is zooming out, the min(0) should be maintained whereas the max should be allowed to increase.
May i is it possible to detect the type of action performed on the chart, panning, zooming? If not any other method for me to achieve the above?

Thank you in advance.

Posts: 105
Joined: Wed Mar 27, 2019 1:05 pm

Re: Limit the display range on ViewXY

Post by Arction_LasseP » Tue Jun 16, 2020 1:38 pm


We have events which can be very useful here.

BeforePanning event for the view triggers right before the actual panning operation happens. Inside the event you could check the new axis values, for instance if minimum is below zero, and act accordingly. You can actually cancel the panning by setting e.Cancel to true.

Code: Select all

_chart.ViewXY.BeforePanning += ViewXY_BeforePanning;

private void ViewXY_BeforePanning(object sender, BeforePanningXYEventArgs e)
    if (e.XRanges[0].NewMin < 0)
        e.Cancel = true;
BeforeZooming event works very similarly, but it triggers before a zooming action happens. A similar check can be used here but this time you don't want to cancel the zooming since the maximum value should still be changed. Instead, you can set axis minimum directly to 0. This could also be done in BeforePanning -event instead of canceling.

Code: Select all

_chart.ViewXY.BeforeZooming += ViewXY_BeforeZooming;

private void ViewXY_BeforeZooming(object sender, BeforeZoomingXYEventArgs e)
    if (e.XRanges[0].NewMin < 0)
        _chart.ViewXY.XAxes[0].Minimum = 0;
There is also RangeChanged -event for the axes, which triggers whenever axis range has changed. This event could also be used but it will be trickier as any action can trigger the event, not just zooming or panning. Therefore, some logic has to be implemented to detect which action was used. Furthermore, it is always possible to create an eternal loop if axis ranges are being changed inside this event.

Hope this is helpful.
Kind regards,