I would like to have the same scale on both axes (X and Y). I know that it could depend on screen resolution, but I would like to have '1 unit' on both axes to have exactly the same length.
Is it possible?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Let me describe my chart:
1. It has 4 units on X axis and 4 units on Y axis.
2. I can see that my chart is not a square - it is a rectangle (units on X axis are wider than units on Y axis).
3. I draw a line from (1, 1) to (3, 3) and definitely there is not 45 degree angle.
One more thing: size of my ZedGraph control is 600 : 400.
Still I have no clue what I am doing wrong.
Placek
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
You can do this by adjusting the (for example) YAxis scale range to always maintain a 1:1 pixel aspect ratio. To do this, first make a SetSize() method that gets called in response to a ReSize event (like to example code). In your SetSize method, do this:
//fix the X scale, let the Y scale vary to pixel 1:1 aspect ratio
GraphPane pane = zedGraphControl1.GraphPane;
double xPixPerUnit = pane.AxisRect.Width / ( pane.XAxis.Scale.Max - pane.XAxis.Scale.Min );
pane.YAxis.Scale.Max = pane.AxisRect.Height / xPixPerUnit + pane.YAxis.Scale.Min;
pane.YAxis.Scale.MinAuto = false;
zedGraphControl1.AxisChange();
Be sure to call AxisChange() and then SetSize() when you first setup your graph.
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is what I did:
1. In Form_Load I am creating my chart, which axes are of text type.
2. At the end of that method I have following lines:
zedGraphControl1.AxisChange();
SetSize(this, null);
3. My SetSize method is the following:
private void SetSize(object sender, EventArgs e)
{
//fix the X scale, let the Y scale vary to pixel 1:1 aspect ratio
GraphPane pane = zedGraphControl1.GraphPane;
double xPixPerUnit = pane.AxisRect.Width / (pane.XAxis.Scale.Max - pane.XAxis.Scale.Min);
pane.YAxis.Scale.Max = pane.AxisRect.Height / xPixPerUnit + pane.YAxis.Scale.Min;
pane.YAxis.Scale.MinAuto = false;
zedGraphControl1.AxisChange();
}
4. In response to ReSize event SetSize method is called.
I run my code and still unit on X axis is wider than unit on Y axis.
What am I missing?
Placek
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What exactly are you seeing? As you resize, the scale on the Y axis should change so that a the units are square. If you draw a line from (1,1) to (100,100), it should be a true 45 degree angle.
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi.
I would like to have the same scale on both axes (X and Y). I know that it could depend on screen resolution, but I would like to have '1 unit' on both axes to have exactly the same length.
Is it possible?
Let me describe my chart:
1. It has 4 units on X axis and 4 units on Y axis.
2. I can see that my chart is not a square - it is a rectangle (units on X axis are wider than units on Y axis).
3. I draw a line from (1, 1) to (3, 3) and definitely there is not 45 degree angle.
One more thing: size of my ZedGraph control is 600 : 400.
Still I have no clue what I am doing wrong.
Placek
Hi,
You can do this by adjusting the (for example) YAxis scale range to always maintain a 1:1 pixel aspect ratio. To do this, first make a SetSize() method that gets called in response to a ReSize event (like to example code). In your SetSize method, do this:
//fix the X scale, let the Y scale vary to pixel 1:1 aspect ratio
GraphPane pane = zedGraphControl1.GraphPane;
double xPixPerUnit = pane.AxisRect.Width / ( pane.XAxis.Scale.Max - pane.XAxis.Scale.Min );
pane.YAxis.Scale.Max = pane.AxisRect.Height / xPixPerUnit + pane.YAxis.Scale.Min;
pane.YAxis.Scale.MinAuto = false;
zedGraphControl1.AxisChange();
Be sure to call AxisChange() and then SetSize() when you first setup your graph.
John
Thanks John.
I tried your solution, but I does not work.
This is what I did:
1. In Form_Load I am creating my chart, which axes are of text type.
2. At the end of that method I have following lines:
zedGraphControl1.AxisChange();
SetSize(this, null);
3. My SetSize method is the following:
private void SetSize(object sender, EventArgs e)
{
//fix the X scale, let the Y scale vary to pixel 1:1 aspect ratio
GraphPane pane = zedGraphControl1.GraphPane;
double xPixPerUnit = pane.AxisRect.Width / (pane.XAxis.Scale.Max - pane.XAxis.Scale.Min);
pane.YAxis.Scale.Max = pane.AxisRect.Height / xPixPerUnit + pane.YAxis.Scale.Min;
pane.YAxis.Scale.MinAuto = false;
zedGraphControl1.AxisChange();
}
4. In response to ReSize event SetSize method is called.
I run my code and still unit on X axis is wider than unit on Y axis.
What am I missing?
Placek
What exactly are you seeing? As you resize, the scale on the Y axis should change so that a the units are square. If you draw a line from (1,1) to (100,100), it should be a true 45 degree angle.
John