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

Questions about zooming and panning

1 Answer 106 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Franz
Top achievements
Rank 2
Franz asked on 17 Dec 2011, 05:32 PM
Hello,

I'm using a line series on a DateTimeCategoricalAxis and have two questions about zooming and panning.
1. how can I get the maxium offset value so i can start out on a zoom level and scroll to the last value in the chart?
2. how can I get the the first and the last visible value (datapoint) of a chart so I can display a the date range on a label?

Regards
Franz

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 20 Dec 2011, 12:00 PM
Hi Franz,

Thank you for contacting us and for your questions.

1. The maximum PanOffset along the horizontal axis may be calculated like this:

double plotAreaWidth = this.radChart1.PlotAreaClip.Width;
double zoomWidth = this.radChart1.Zoom.Width * plotAreaWidth;
double maxOffsetX = plotAreaWidth - zoomWidth;

Please note that the initial layout pass should be finished so that the chart model is properly laid-out. So, you will need to hook-up the LayoutUpdated method of the chart and update the PanOffset in the handler.

2. The chart tracks that information but it is currently internal. We will consider exposing it publicly. A possible solution would be to manually find the points, using the PlotAreaClip property:

private DataPoint[] FindFirstLastVisiblePoints(CategoricalSeries series)
{
    DataPoint firstPoint = null;
    DataPoint lastPoint = null;
    RadRect plotArea = this.radChart1.PlotAreaClip;
 
    foreach (DataPoint point in series.DataPoints)
    {
        if (point.LayoutSlot.IntersectsWith(plotArea))
        {
            if (firstPoint == null)
            {
                firstPoint = point;
            }
            lastPoint = point;
        }
    }
 
    return new DataPoint[] { firstPoint, lastPoint };
}

The IntersectsWith method has a bug in it (will be fixed in the upcoming Service Pack 1) and will not work properly if a vertical zoom is applied.

I hope this information is useful. Let me know if I can assist you further.

All the best,
Georgi
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Franz
Top achievements
Rank 2
Answers by
Georgi
Telerik team
Share this question
or