I am making a chart in C# using custom labels on the X-axis. The scale is in dates, and it changes based on the selected values (from one month to two years). It works well and the width of the chart stays constant whenever I change the value of the scale; it just adjusts the bar width.
The problem happens when I try to rotate the labels. When I do, it resizes all of the bars differently on each different scale and never takes up the same amount of space as the originals. I want to be able to rotate the labels without resizing everything. Can I do this? Why is this happening? How can I fix it?
The code I'm using to add the custom labels is this:
DateTime StartMonthPos = XValues[0];
DateTime EndPos = new DateTime();
if (Time == 6 || Time == 12 || Time == 24)
{
foreach (DateTime Date in XValues)
{
EndPos = Date;
if (Date.Month != month)
{
Chart4.ChartAreas[0].AxisX.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 0, LabelMarkStyle.None);
StartMonthPos = Date;
}
month = Date.Month;
}
XAxis.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 0, LabelMarkStyle.None);
}
else
{
foreach (DateTime Date in XValues)
{
EndPos = Date;
Chart4.ChartAreas[0].AxisX.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("M"), 0, LabelMarkStyle.None);
StartMonthPos = Date;
}
XAxis.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("M"), 0, LabelMarkStyle.None);
}
If I add this line of code after that, things get messed up:
Chart4.ChartAreas[0].AxisX.LabelStyle.Angle = 0;
Here is a picture from before the problematic code:
And here is the after picture: