图表控件TeeChart for .NET系列教程四:轴控制(中)

图表控件TeeChart for .NET系列教程四:轴控制(中)

TeeChart for .NET是优秀的工业4.0 WinForm图表控件,官方独家授权汉化,集功能全面、性能稳定、价格实惠等优势于一体。TeeChart for .NET 中文版还可让您在使用和学习上没有任何语言障碍,至少可以节省30%的开发时间。

TeeChart for .NET最新版下载

在TeeChar系列教程中,上一章我们主要讲解了如何实现轴控制(上),今天我们继续为大家讲解“如何实现轴控制(中)”。

注意 
当改变轴标签频率时,请记住,TeeChart将根据AxisLabels.Separation属性的设置来避免标签重叠。这意味着,如果标签频率太高,标签无法适应,那么TeeChart将分配 “最适合”。改变标签角度和标签分离是2个选项,可以帮助你适合你需要的标签。参见标签部分和AxisLabels.Angle属性。
标题
标题是在轴页的标题部分设置的。你可以改变轴的标题文本及其字体和阴影属性。标题文本的角度和大小也可以被指定。关于运行时间,请看 AxisTitle 类。
标签
请参阅AxisLabels类,了解标签属性的简历。
注意 
当改变轴标签频率时,请记住,TeeChart将根据AxisLabels.Separation属性的设置来避免标签重叠。这意味着,如果标签频率太高,标签无法适应,那么TeeChart将分配 “最适合”。改变标签角度和标签分离是2个选项,可能有助于你适合你所需要的标签。参见AxisLabels.Angle属性。

标签格式 
你可以将所有标准的数字和日期格式应用于轴的标签。轴页,标签部分包含 “数值格式 “字段。如果你的数据是日期时间,字段名就会变成 “日期时间格式”。在运行时使用。

[C#.Net] tChart1.Axes.Bottom.Labels.ValueFormat = "#,##0.00;(#,##0.00)";  [VB.Net] With TChart1.Axes.Bottom    .Labels.ValueFormat = "#,##0.00;(#,##0.00)" End With 

或者对于日期时间数据

[C#.Net] tChart1.Axes.Bottom.Labels.DateTimeFormat = "dddd/MMMM/yyyy";  [VB.Net] With TChart1.Axes.Bottom    .Labels.DateTimeFormat = "dddd/MMMM/yyyy" End With MultiLine labels 

轴标签可以显示为多行文本,而不是单行文本。行与行之间用LineSeparator字符()分开。
举例

[C#.Net] bar1.Add(1234, "New" + Steema.TeeChart.Texts.LineSeparator + "Cars", Color.Red); bar1.Add(2000, "Old" + Steema.TeeChart.Texts.LineSeparator + "Bicycles", Color.Red); tChart1.Panel.MarginBottom = 10;  [VB.Net] Bar1.Add(1234, "New" + Steema.TeeChart.Texts.LineSeparator + "Cars", Color.Red) Bar1.Add(2000, "Old" + Steema.TeeChart.Texts.LineSeparator + "Bicycles", Color.Red) TChart1.Panel.MarginBottom = 10 

日期时间标签的例子
下面将用两行文字显示底轴标签,一行显示月和日,第二行显示年。
2月28日 3月1日 …
2003 2003 ..

[C#.Net] bar1.Add(DateTime.Parse("28/2/2003"), 100, Color.Red); bar1.Add(DateTime.Parse("1/3/2003"), 200, Color.Red); bar1.Add(DateTime.Parse("2/3/2003"), 150, Color.Red); bar1.XValues.DateTime = true; tChart1.Axes.Bottom.Labels.DateTimeFormat = "MM/dd hh:mm"; tChart1.Axes.Bottom.Labels.MultiLine = true; tChart1.Panel.MarginBottom = 10;      [VB.Net] Bar1.Add(DateValue("28/2/2003"), 100, Color.Red) Bar1.Add(DateValue("1/3/2003"), 200, Color.Red) Bar1.Add(DateValue("2/3/2003"), 150, Color.Red) Bar1.XValues.DateTime = True TChart1.Axes.Bottom.Labels.DateTimeFormat = "MM/dd hh:mm" TChart1.Axes.Bottom.Labels.MultiLine = True TChart1.Panel.MarginBottom = 10 

将AxisLabels.MultiLine属性设置为True将自动在有空格的地方分割标签,有效地将标签分成两行。
第一行为’mm/dd
第二行为’hh:mm’。 
在运行时,你总是可以使用OnGetAxisLabel事件,以编程方式将标签分成几行。

[C#.Net] private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.TChart.GetAxisLabelEventArgs e)                      string myLabelText = e.LabelText;             tChart1.Axes.Bottom.Labels.SplitInLines(ref myLabelText, " ");             e.LabelText = myLabelText;           [VB.Net] Private Sub TChart1_GetAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.TChart.GetAxisLabelEventArgs) Handles TChart1.GetAxisLabel         Dim myLabelText As String         myLabelText = e.LabelText         TChart1.Axes.Bottom.Labels.SplitInLines(myLabelText, " ")         e.LabelText = myLabelText End Sub 

在上面的例子中,全局 “TeeSplitInLines “程序将 “LabelText “中的所有空格转换为行的分隔符(回车)。
轴AxisLabels.Angle属性也可以用于多行轴标签。
定制轴的标签

进一步的标签控制可以通过使用轴事件来获得。这些事件允许你激活/停用/改变任何一个轴的标签。下面的例子修改了每个Label,在点的索引值前面加上一个文本短语。

[C#.Net] private void button1_Click(object sender, System.EventArgs e)                      bar1.FillSampleValues(20);             tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Mark;           private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.TChart.GetAxisLabelEventArgs e)                      if(((Steema.TeeChart.Axis)sender).Equals(tChart1.Axes.Bottom))             e.LabelText = "Period " + Convert.ToString(e.ValueIndex);           [VB.Net] Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click         Bar1.FillSampleValues(20)         TChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Mark End Sub  Private Sub TChart1_GetAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.TChart.GetAxisLabelEventArgs) Handles TChart1.GetAxisLabel         If CType(sender, Steema.TeeChart.Axis) Is TChart1.Axes.Bottom Then             e.LabelText = "Period " & e.ValueIndex         End If End Sub 

关于用Axis事件定制标签的更多信息,请参见题为 “轴事件 “的章节。

如果您想了解TeeChart for .NET价格,欢迎咨询在线客服

TeeChart for .NET 是优秀的工业4.0 WinForm图表控件,官方独家授权汉化,集功能全面、性能稳定、价格实惠等优势于一体。

TeeChart for .NET技术交流QQ群:  欢迎加入

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年11月18日
下一篇 2022年11月19日

相关推荐

发表回复

登录后才能评论