PanOffset Calculation Problems

3 posts, 1 answers
  1. Yisselda
    Yisselda avatar
    2 posts
    Member since:
    Mar 2015

    Posted 31 Mar 2015 Link to this post

    Hello,

    I am trying to zoom and change the offset on the horizontal and vertical axis from code behind.
    The code seems to work for the horizontal axis but not the vertical.

    For example, I have a vertical axis displaying [0; 10]. I want to see [5,6], but the chart displays the [9,10] interval.
    I have checked the virtualHeight (in this case 6850.0) and new value of the panoffset seems good => 3425.0

    Why do I have this behaviour ? Is there a property that need to be set ?

    01.public static void ZoomInChart(RadCartesianChart chart, double absmin, double absmax, double ordmin, double ordmax)
    02.        {
    03.            if (chart != null)
    04.            {
    05.                double absMaxValue = ((Telerik.Windows.Controls.ChartView.NumericalAxis)(chart.HorizontalAxis)).ActualRange.Maximum;
    06.                double absMinValue = ((Telerik.Windows.Controls.ChartView.NumericalAxis)(chart.HorizontalAxis)).ActualRange.Minimum;
    07.                double absMaxDelta = Math.Abs(absMaxValue - absMinValue);
    08.                double absDelta = Math.Abs(absmax - absmin);
    09. 
    10.                double abscoef = absDelta == 0 || double.IsNaN(absDelta) ? 1 : absMaxDelta / absDelta;
    11.                 
    12.                double ordMaxValue = ((Telerik.Windows.Controls.ChartView.NumericalAxis)(chart.VerticalAxis)).ActualRange.Maximum;
    13.                double ordMinValue = ((Telerik.Windows.Controls.ChartView.NumericalAxis)(chart.VerticalAxis)).ActualRange.Minimum;
    14.                double ordMaxDelta = Math.Abs(ordMaxValue - ordMinValue);
    15.                double ordDelta = Math.Abs(ordmax - ordmin);
    16.                                 
    17.                double ordcoef = ordDelta == 0 || double.IsNaN(ordDelta) ? 1 : ordMaxDelta / ordDelta;
    18. 
    19.                chart.Zoom = new Size(abscoef, ordcoef);
    20. 
    21.                double virtualWidth = chart.PlotAreaClip.Width * chart.Zoom.Width;
    22.                 
    23.                double virtualHeight = chart.PlotAreaClip.Height * chart.Zoom.Height;
    24. 
    25.                // Produit en croix pour trouver la valeur du nouvel origine
    26.                double absVal = (virtualWidth * (absmin - absMinValue)) / absMaxDelta;
    27. 
    28.                double ordVal = (virtualHeight * (ordmin - ordMinValue)) / ordMaxDelta;
    29.                 
    30.                if (!double.IsNaN(absVal) && !double.IsNaN(ordVal))
    31.                {
    32.                    chart.PanOffset = new Point(-absVal, -ordVal);
    33.                }
    34.            }
    35.        }
  2. Answer
    Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 01 Apr 2015 Link to this post

    Hello Yisselda,

    The RadCartesianChart exposes VerticalZoomRangeStart and End properties which should allow you to zoom in where you need, in relative values. Say that the range is (0, 50) and you need to zoom in at (15, 30) - in this case you need to set the relative zoom start/end to (0.3, 0.6). I hope this helps.

    Regards,
    Petar Marchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Yisselda
    Yisselda avatar
    2 posts
    Member since:
    Mar 2015

    Posted 01 Apr 2015 in reply to Petar Marchev Link to this post

    Thank you very much. I didn't know about these properties.
    Using them works great works great !

    So I changed my code like this : 

                         // Produit en croix pour trouver la valeur du nouvel origine
                    double absValStart = (absmin - absMinValue) / absMaxDelta;
                    double ordValStart = (ordmin - ordMinValue) / ordMaxDelta;
                    double absValEnd = (absmax - absMinValue) / absMaxDelta;
                    double ordValEnd = (ordmax - ordMinValue) / ordMaxDelta;
     
                    chart.HorizontalZoomRangeStart = absValStart;
                    chart.VerticalZoomRangeStart = ordValStart;
     
                    chart.HorizontalZoomRangeEnd = absValEnd;
                    chart.VerticalZoomRangeEnd = ordValEnd;
Back to Top