This is a migrated thread and some comments may be shown as answers.

PanOffset Calculation Problems

2 Answers 90 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Yisselda
Top achievements
Rank 1
Yisselda asked on 31 Mar 2015, 04:25 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Petar Marchev
Telerik team
answered on 01 Apr 2015, 07:17 AM
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.

 
0
Yisselda
Top achievements
Rank 1
answered on 01 Apr 2015, 09:37 AM
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;
Tags
ChartView
Asked by
Yisselda
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Yisselda
Top achievements
Rank 1
Share this question
or