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

Set initial zoom level of the 3D chart?

1 Answer 103 Views
Chart
This is a migrated thread and some comments may be shown as answers.
GPJ
Top achievements
Rank 1
GPJ asked on 29 Apr 2009, 03:58 PM
How can I set the initial zoom level of the 3d chart?  In my situation, the 3D pie chart fills only a small fraction of the available space available.  The user can't interact with the chart, so it needs to happen when the chart gets created.

Thanks
Greg

1 Answer, 1 is accepted

Sort by
0
Accepted
Dwight
Telerik team
answered on 30 Apr 2009, 10:56 AM
Hello Greg,

Here is an example, in which I have created a method that zooms the chart by a factor (by calculating new position for the camera):
public partial class Window1 : Window 
    private double[] data = new double[] { 
        12, 50, 11, 44, 55, 77
    }; 
 
    public Window1() 
    { 
        Random r = new Random(0xa713); 
        InitializeComponent(); 
        DataSeries series = new DataSeries(); 
        series.Definition = new Pie3DSeriesDefinition(); 
 
        foreach(double value in this.data) 
            series.Add(new DataPoint() { YValue = value }); 
 
        chart1.DefaultView.ChartArea.DataSeries.Add(series); 
        this.Loaded += OnLoaded; 
    } 
 
    private void OnLoaded(object sender, RoutedEventArgs e) 
    { 
        ZoomChartArea(chart1.DefaultView.ChartArea, 2); 
    } 
 
    private static void ZoomChartArea(ChartArea chartArea, double zoom) 
    { 
        Viewport3D viewport3D = chartArea.Template3D.FindName("PART_ViewPort3D", chartArea) as Viewport3D; 
 
        if (viewport3D == null
            return
 
        PerspectiveCamera camera = viewport3D.Camera as PerspectiveCamera; 
 
        if (camera == null
            return
 
        Vector3D vector = (Vector3D)camera.Position; 
        Vector3D lookDirection = camera.LookDirection; 
        lookDirection.Normalize(); 
        lookDirection *= (vector.Length - vector.Length / zoom); 
        Point3D newPosition = (Point3D)(vector + lookDirection); 
 
        PerspectiveCamera newCamera = camera.Clone(); 
        newCamera.Position = newPosition; 
        viewport3D.Camera = newCamera; 
    } 

Let me know if that solution is not suitable for your case.

Best regards,
Evtim
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Chart
Asked by
GPJ
Top achievements
Rank 1
Answers by
Dwight
Telerik team
Share this question
or