C#图表对齐轴标签

编程入门 行业动态 更新时间:2024-10-27 22:25:26
本文介绍了C#图表对齐轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在列图表中有一些自定义标签(我的代码中有一些):

I have some custom labels in column chart (a bit of my code):

chart.ChartAreas[0].AxisX.IsMarginVisible = true; chart.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = true; chart.ChartAreas[0].AxisX.LineColor = Color.LightGray; chart.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray; chart.ChartAreas[0].AxisX.LabelStyle.Angle = 0; chart.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Trebuchet MS", 10); chart.ChartAreas[0].AxisX.MajorTickMark.LineColor = Color.LightGray; chart.ChartAreas[0].AxisX.Interval = 1; chart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Weeks; chart.ChartAreas[0].AxisX.IsLabelAutoFit = true; chart.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = false; DateTime minDate = DateTime.Parse(dt.Rows[0]["Date"].ToString()); DateTime maxDate = DateTime.Parse(dt.Rows[dt.Rows.Count - 1]["Date"].ToString()); for (int i = 0; i < dt.Rows.Count - 1; i++) { chart.ChartAreas[0].AxisX.CustomLabels.Add(new CustomLabel(minDate.ToOADate(), minDate.AddDays(6).ToOADate(), minDate.ToShortDateString() + "-" + minDate.AddDays(6).ToShortDateString(), 0, LabelMarkStyle.None)); minDate = minDate.AddDays(7); }

因为我的自定义文本太长了 minDate .ToShortDateString()+ - + minDate.AddDays(6).ToShortDateString()它看起来像

So since my custom lable text is so long minDate.ToShortDateString() + "-" + minDate.AddDays(6).ToShortDateString() it looks like

如何移动到左轴lables如果i可以?

How can i moved to the left axis lables if i can?

推荐答案

除了缩短内容以避免任何冗余外,您可以尝试通过添加一些空格来欺骗标签格式化,然后是不间断空格,然后是\\\。

Besides shortening the content to avoid any redundancy you could try to trick the label formatter by adding a few blanks to the right, then a non-breaking space and then a \n.

以下是之前和之后的结果:

Here is the result before and after:

我使用了以下代码:

A.AxisX.LabelStyle.Format = "MM.dd.yy"; A.AxisX.LabelStyle.Format = "MM.dd.yy " + ((char)160) + "\n";

更多推荐

C#图表对齐轴标签

本文发布于:2023-07-20 05:03:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1164463.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图表   标签

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!