c# – 在.NET图表中仅使用X轴中的自定义标签
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 在.NET图表中仅使用X轴中的自定义标签,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1619字,纯文字阅读大概需要3分钟。
内容图文
![c# – 在.NET图表中仅使用X轴中的自定义标签](/upload/InfoBanner/zyjiaocheng/823/a29b4cfcfed54f409224eb7ac39f9b96.jpg)
我在C#中创建一个.NET线图,X轴间隔为几周.对于我的项目,我只想使用自定义标签,但是现在我仍然需要网格线.有没有人知道在保留自定义标签的同时隐藏默认X轴标签的方法?
我试过这个:
Chart4.ChartAreas[0].AxisX.LabelStyle.Enabled = false;
显而易见的结果是没有应用标签,这不是我想要做的.
编辑:
生成原始行的代码是这样的:
Chart4.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "M";
自定义标签的代码是这样的:
int month = XValues[0].Month;
var XAxis = Chart4.ChartAreas[0].AxisX;
DateTime StartMonthPos = XValues[0];
DateTime EndPos = new DateTime();
foreach (DateTime Date in XValues)
{
EndPos = Date;
if (Date.Month != month)
{
Chart4.ChartAreas[0].AxisX.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 1, LabelMarkStyle.None);
StartMonthPos = Date;
}
month = Date.Month;
}
XAxis.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 1, LabelMarkStyle.None);
该图表如下所示:
它看起来应该是这样的:
解决方法:
好吧,我在MSDN上查看了Label控件.为了使自定义标签出现在普通标签的位置,我将RowIndex参数设置为0,替换默认标签行.自定义行的最终代码如下所示:
int month = XValues[0].Month;
var XAxis = Chart4.ChartAreas[0].AxisX;
DateTime StartMonthPos = XValues[0];
DateTime EndPos = new DateTime();
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);
内容总结
以上是互联网集市为您收集整理的c# – 在.NET图表中仅使用X轴中的自定义标签全部内容,希望文章能够帮你解决c# – 在.NET图表中仅使用X轴中的自定义标签所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。