Re: Limit the display range on ViewXY
Posted: Tue Jun 16, 2020 1:38 pm
Hello,
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.
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.
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,
Lasse
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;
}
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;
}
Hope this is helpful.
Kind regards,
Lasse