gpt4 book ai didi

c# - .NET 图表自定义标签旋转

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:49 25 4
gpt4 key购买 nike

我在 C# 中使用 X 轴上的自定义标签制作图表。比例以日期为单位,它会根据所选值(从一个月到两年)发生变化。它运行良好,每当我更改比例值时,图表的宽度都保持不变;它只是调整条形宽度。

当我尝试旋转标签时出现问题。当我这样做时,它会在每个不同的比例上以不同的方式调整所有条形图的大小,并且永远不会占用与原始条形图相同的空间量。我希望能够在不调整所有内容的情况下旋转标签。我可以这样做吗?为什么会这样?我该如何解决?

我用来添加自定义标签的代码是这样的:

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);
}

如果我在那之后添加这行代码,事情就会变得一团糟:

 Chart4.ChartAreas[0].AxisX.LabelStyle.Angle = 0;

这是问题代码之前的图片:

Enter image description here

这是后图:

Enter image description here

最佳答案

尽管该帖子涉及相当多的 XAML...

如您所见,单靠这条线无法实现旋转:

Chart4.ChartAreas[0].AxisX.LabelStyle.Angle = 0;

还有更多的旋转 ;)

关于c# - .NET 图表自定义标签旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14106253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com