Reputation: 378
Does anybody now how to prevent the Y-axis from moving (horizontally) when the text area increases (for example when displaying 100 instead of 1 on a label on the Y-axis).
The following image illustrates the problem; when a decimal is added to the number on the labels, the diagram is resized and the Y-axis is moved to the right:
Upvotes: 0
Views: 280
Reputation: 54433
The reason the Axis
and other a few other ChartElements
may move is that their Positions
are set to Automatic
by default; so when the lables need more space they get it and the inner portion is reduced.
So if you want to prevent that you need to set an explicit values for the X
values of its Position
.
Note that the values are in percent of the respective containers.
Unless you set a special Crossing
value, the primary axes are always drawn to the left and bottom of the InnerPlotArea
.
So you want to set the position, maybe like this:
ChartArea ca = chart1.ChartAreas[0];
ca.InnerPlotPosition.X = 10;
Note however, that this means: The Y-Axis
will start at 10%
of the whole
ChartArea.Width
, which usually means something like 'almost 10%'
of the whole Chart.Width
. (The Legend
and some white space will usually take some space, too).
So if you resize your chart the axis may sit a little too much to the right.. You may want ot play with the number and maybe code an extra line in the Resize
event of the Chart.
Upvotes: 1