Set initial zoom level of the 3D chart?

2 posts, 1 answers
  1. GPJ
    GPJ avatar
    31 posts
    Member since:
    Oct 2008

    Posted 29 Apr 2009 Link to this post

    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
  2. Answer
    Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 30 Apr 2009 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top