How to ensure square plot area?

Nov 20, 2012 at 7:47 AM

Hi,

In my application, I need to ensure that the actual plot area where the chart is drawn in always square.

Please advice - sample code welcome.

Thanks,

Warm Regards,

- Vikram

Coordinator
Nov 26, 2012 at 6:12 AM

I think you can change the "PlotMargins" of the plot each time the size of the plot changes...

Or make sure the size of the control is square (handle the sizechanged event on the control or override the coerce value callbacks on the width/height dependency properties?). 

Nov 26, 2012 at 6:42 AM

Thanks for your reply.

 

I understand that I need to adjust plot margins in resize event of the control. I am not clear about the calculation. I have adjusted margins using height / width of the control, and height / width of the title area. This still does not make the plot area square. Here is my calculation:

        private void AdjustPoincareChartMargins(Plot plot, double dWidth, double dHeight)
        {
            Debug.WriteLine("Available W: " + dWidth + ", H: " + dHeight);

            plot.Model.IsLegendVisible = false;
            var availableWidth = dWidth;
            var availableHeight = dHeight - plot.Model.TitleArea.Height;

            var horzMargin = Math.Max(0, (availableWidth - availableHeight)) / 2;
            var vertMargin = Math.Max(0, (availableHeight - availableWidth)) / 2;

            plot.Model.PlotMargins = new OxyPlot.OxyThickness(horzMargin, vertMargin, horzMargin, vertMargin);

            Debug.WriteLine("Plot W: " + plot.Model.PlotArea.Width + ", H: " + plot.Model.PlotArea.Height);
            Debug.WriteLine("PlotAndAxisArea W: " + plot.Model.PlotAndAxisArea.Width + ", H: " + plot.Model.PlotAndAxisArea.Height);
        }

Thanks,
- Vikram