3D Chart Maintain Aspect Ratio

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
User avatar
blakeadkins
Posts: 44
Joined: Tue Feb 25, 2014 7:49 pm

3D Chart Maintain Aspect Ratio

Post by blakeadkins » Mon Nov 23, 2015 4:15 pm

Is there an easy way to get a 3D chart to maintain the ratio of the window. i.e. set dimensions to window size and then have the dimensions and/or zoom auto adjust when window size is changed?

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: 3D Chart Maintain Aspect Ratio

Post by ArctionPasi » Wed Nov 25, 2015 3:56 pm

If using perspective camera (View3D.Camera.OrthographicCamera == False), I think it's better to adjust camera distance.

Code: Select all

   void m_chart_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            const double RegularCamDistance = 200;
            double dAspectRToKeepWH = 1.5;
            double dAspectR = (double)m_chart.ActualWidth / (double)m_chart.ActualHeight;
            if (dAspectR > dAspectRToKeepWH)
            {
                m_chart.View3D.Camera.ViewDistance = RegularCamDistance;
            }
            else
            {
                m_chart.View3D.Camera.ViewDistance = RegularCamDistance / dAspectR * dAspectRToKeepWH;
            }
        }
 
Then the chart shows correctly also in narrow window.
W/H ratio large
W/H ratio large
aspect1.jpg (71.28 KiB) Viewed 6115 times
W/H ratio small
W/H ratio small
aspect2.jpg (44.77 KiB) Viewed 6115 times
LightningChart Support Team, PT

Post Reply