Fixed Y axis

Nov 29, 2011 at 12:00 PM

Hey

How can I set the y axis so it always displays a fixed range? Like 0 to 100 no matter what data I receive?

Thanks in advance

Dec 9, 2011 at 11:55 AM

Here is how I solved my problem.

    public class DisplayRange
    {
        public double Start { get; set; }
        public double End { get; set; }

        public DisplayRange(double start, double end)
        {
            Start = start;
            End = end;
        }

    }

    public class ViewportAxesRangeRestriction : IViewportRestriction
    {

        public DisplayRange XRange = null;
        public DisplayRange YRange = null;


        public Rect Apply(Rect oldVisible, Rect newVisible, Viewport2D viewport)
        {

            if (XRange != null)
            {
                newVisible.X = XRange.Start;
                newVisible.Width = XRange.End - XRange.Start;
            }
           
            if (YRange != null)
            {
                newVisible.Y = YRange.Start;
                newVisible.Height = YRange.End - YRange.Start;
            }

            return newVisible;
        }

      
        public event EventHandler Changed;
    }

 

.....

            plotter.Viewport.AutoFitToView = true;
            ViewportAxesRangeRestriction restr = new ViewportAxesRangeRestriction();
            restr.YRange = new DisplayRange(-5, 105);
            plotter.Viewport.Restrictions.Add(restr);

.....

Aug 29, 2012 at 12:01 PM

Excellent!  Exactly what I needed thanks for sharing.

Sep 13, 2013 at 10:06 AM
Do you have any idea how can I apply this code for setting ranges for DateTime Axis?
Nov 12, 2013 at 3:14 PM
What d3 version you are using?

I am not getting ViewportAxesRangeRestriction in the current stable release.

Which version includes all the properties of d3?

Vishal N