Page 1 of 1

Limiting axis range to limits

Posted: Thu Jun 06, 2013 1:34 pm
by SupportArchives
I want to limit the range of X axis between 0 and 20, preventing the user to pan or zoom to beyond those limits. How to achieve that?

Re: Limiting axis range to limits

Posted: Thu Jun 06, 2013 1:37 pm
by ArctionPasi
Set RangeChanged event handler for the X Axis:

Code: Select all

void ExamplePointLineSeriesXY_RangeChanged(double newMin, double newMax, AxisBase axis, ref bool cancelRendering)
        {
            double LimitMin = 0; 
            double LimitMax = 20; 

            double dMin = newMin; 
            double dMax = newMax;

            bool bLimited = false;
            if (newMin < LimitMin)
            {
                dMin = LimitMin;
                bLimited = true; 
            }
            if (newMax > LimitMax)
            {
                dMax = LimitMax;
                bLimited = true; 
            }

            if (bLimited)
            {
                cancelRendering = true; //Cancel the ongoing rendering phase 

                axis.SetRange(dMin, dMax); //Render manually here 
            }

        }

Re: Limiting axis range to limits

Posted: Thu Jun 06, 2013 2:36 pm
by jhyap
I would like to try this on tomorrow. But I do not have Visual Studio to hands on now. So, I would like to ask a real quick question: Where can I find the RangeChange event handler?

Is it find it here?

Code: Select all

lightingChartUltimate1.ViewXY.XAxes[0].here
:D

Re: Limiting axis range to limits

Posted: Thu Jun 06, 2013 3:08 pm
by ArctionPasi
Yes, there it is :mrgreen: