I use the Chart component to draw some graphics. The size of the Chart component itself is rectangular (the width in pixels is greater than the height). But the size of the area of ​​the graph should be strictly square. How do I do:

ChartGraphic.ChartAreas[0].Position.Height = 70; ChartGraphic.ChartAreas[0].Position.Width = 70; ChartGraphic.ChartAreas[0].Position.X = 3; ChartGraphic.ChartAreas[0].Position.Y = 10; 

It turns out like this: enter image description here

As you can see - the coordinate system itself is not square. How to set it up correctly?

    1 answer 1

    The chart has the ChartArea property, and it, in turn, has the Position property, which allows you to specify the position and size of the chart relative to the parent control as a percentage. Approximate code to be placed in the Resize event so that the graph is always strictly square:

     ChartGraphic.ChartAreas[0].Position.X = 3; ChartGraphic.ChartAreas[0].Position.Y = 1; if (ChartGraphic.Width < ChartGraphic.Height) { ChartGraphic.ChartAreas[0].Position.Width = 90; ChartGraphic.ChartAreas[0].Position.Height = (float)(ChartGraphic.Width / 100.0 * 90 * 100) / ChartGraphic.Height; } else { ChartGraphic.ChartAreas[0].Position.Height = 90; ChartGraphic.ChartAreas[0].Position.Width = (float)(ChartGraphic.Height / 100.0 * 90 * 100) / ChartGraphic.Width; }