Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

wpf square graph axes

Solved!
Go to solution

I need to make ScatterGraph with perfectly square axes, which also should fill its container. It will display the unit circle (radius 1, positioned at 0), so non-square axes are very annoying.

 

What I do now, is something li this, but it doesn't make perfectly square axes.

 

private void graphWrapper_SizeChanged(object sender, SizeChangedEventArgs e)
{
 if (squareArea)
 {
  int size = (int)Math.Max(0, Math.Min(graphWrapper.ActualWidth, graphWrapper.ActualHeight) - 10); 
  graph.Width = size + 35;
  graph.Height = size;
  graph.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
 }
}

0 Kudos
Message 1 of 2
(5,227 Views)
Solution
Accepted by topic author eugenem

You can use the following SizeChanged event handler on a graph to maintain a square plot area:


    private void OnGraphSizeChanged( object sender, SizeChangedEventArgs e ) {
        Thickness margin = graph.Margin;
        Size plotAreaSize = graph.GetPlotAreaSize( );
        Size current = new Size(
            plotAreaSize.Width + margin.Left + margin.Right,
            plotAreaSize.Height + margin.Top + margin.Bottom );
        double ideal = Math.Floor( Math.Min( current.Width, current.Height ) );

        graph.Margin = new Thickness {
            Right = Math.Floor( current.Width - ideal ),
            Bottom = Math.Floor( current.Height - ideal )
        };

~ Paul H
0 Kudos
Message 2 of 2
(5,213 Views)