0

The resulting graphs must be represented in such a way that 1mm (1 unit) horizontal is exactly 1mm (1 unit) vertical (or any other measurement, basically a square in equal units MUST be square, not rectangular in any way).

I am using System.Windows.Forms.DataVisualization.Charting library and working on a Windows Forms application.

chart1.Width= 500;
chart1.Height = 500;
chart1.Legends.Clear();

var area = chart1.ChartAreas[0];
area.AxisX.Minimum = 0;
area.AxisX.Maximum = 10;
area.AxisX.Interval = 1;

area.AxisY.Minimum = 0;
area.AxisY.Maximum = 15;
area.AxisY.Interval = 1;


var lineSeries = chart1.Series[0];
lineSeries.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
//lineSeries.MarkerSize = 3;
lineSeries.BorderWidth = 3;

lineSeries.Points.AddXY(0, 0);
lineSeries.Points.AddXY(2, 2);
lineSeries.Points.AddXY(4, 6);
lineSeries.Points.AddXY(6, 10);
lineSeries.Points.AddXY(10, 10);

And here the output shows height and width ratio of the graph is not proper (width should be 2/3 of the height).

enter image description here

And this output shows height and width of graph is identical and square. If i make both axes equal. e.g.

area.AxisX.Minimum = 0;
area.AxisX.Maximum = 15;
area.AxisX.Interval = 1;

area.AxisY.Minimum = 0;
area.AxisY.Maximum = 15;
area.AxisY.Interval = 1;

enter image description here

Stephen Docy
  • 4,738
  • 7
  • 18
  • 31
Muhammad Umar
  • 1,357
  • 13
  • 14
  • 1
    It looks fine to me. Given that yopur monitor is able to show square pixels you would have to make sure the the InnerPlotPosition of the ChartArea is a square. This is not as easy as it sounds. [Here is aclosely related question](https://stackoverflow.com/questions/36221672/constrain-aspect-ratio-in-windowsforms-datavisualization-chart/36248343#36248343) – TaW Mar 01 '18 at 16:20
  • @TaW Thank you very much for the detailed link. Many confusions about chart sizing and ratio are clear now. – Muhammad Umar Mar 01 '18 at 17:29
  • @Taw I have updated the question and added an image to read "And here the output shows height and width ratio of the graph is not proper (width should be 2/3 of the height)". Any directions on this please? – Muhammad Umar Mar 02 '18 at 13:01
  • Not sure what you mean. By default the chart will make everything as large as possible. So the 1st image is correct as the default. If you want to keep an aspect ratio you need to either resize the chart or its inner areas ie chartare and/or innerplotposition. – TaW Mar 02 '18 at 15:11
  • @Taw If we go with innerplot position, which changes do i need to make in your provided code so that i get the aspect ratio base size instead of whole square? – Muhammad Umar Mar 02 '18 at 15:21

1 Answers1

1

I finally got the answer by @Taw's mentioned post and comments.

Given that your monitor is able to show square pixels you would have to make sure the the InnerPlotPosition of the ChartArea is a square.

Constrain aspect ratio in WindowsForms DataVisualization Chart

Muhammad Umar
  • 1,357
  • 13
  • 14