TeeChart Pro .Net 教程----教程4 - 坐标轴控件
2010-12-22 22:47
791 查看
TeeChart Pro .Net 教程
教程4 - 坐标轴控件
TeeChart Pro会自动为您定义所有坐标轴的标签,它们具有高度的灵活性可适应您任何特定的要求。TeeChart Pro提供了真正的多种坐标轴。在设计或运行时这些内容是可见的,另外它还提供了很多功能并在定义坐标轴时具有高度的灵活性。请参见本教程的各个章节以获得更多信息。
内容
坐标轴控件 - 关键区域
刻度
增量
标题
标签
刻度标记
坐标轴位置
附加坐标轴
复制坐标轴
多种坐标轴
坐标轴事件
OnClickAxis
OnGetAxisLabel
OnGetNextAxisLabel
坐标轴控件 - 关键区域
刻度
当你添加数据序列到您的图表时,坐标轴的刻度会自动进行设置。您可在设计时或运行时通过坐标轴的属性来修改它们。
当添加一个新的数据序列时,在TeeChart编辑器Axis页的Scales部分将显示自动选择和其他灰色的选择。 所有值均为数字。
在一个数据序列上设置一个日期型数据序列为True(该轴)的时候 -> 全部的页面,在TeeChart编辑器轴页的刻度部分将显示自动选择和其他灰色输出。所有值均为日期型。
自动选择最佳的坐标轴刻度范围将会非常适合您的数据。如果您关闭自动选择,那么刻度的部分将变成不可选择项,这时您可以改变坐标轴的值。最重要的是,请您记住在当前页左边的列表框中选择您所想要进行设置的坐标轴。
在设计时使用TeeChart编辑器添加一个线型数据序列到您的图表,然后用下面的代码添加一个命令按钮:
运行按钮中的代码将用40个随机值产生一个线型数据序列。 在设计时转到TeeChart编辑器。在Axis页的底轴刻度部分,将Automatic选项设为“off”,现在您就可以配置坐标轴刻度的最大和最小值。再次运行该代码将显示您为坐标轴设定的值。用鼠标的右键您可以滚动查看到剩余的值。
使用下面的代码您可以在运行时修改最大和最小值:
你可以分别设置坐标轴刻度最大和最小值的自动化属性。例如:
增量
您可以定制坐标轴的间隔。从Axis页刻度部分选择增量组合框并输入您想要的增量值。您也可以在运行时通过以下代码修改这个值:
如果您是日期型数据(您可以通过总体页的数据序列标签设置您的数据序列为日期型),转到Chart标签->Axis页,刻度部分将显示日期范围。从增量组合框所示增量的范围选择并添加一些示例数据:
在运行时修改增量值:
了解更多有关日期坐标轴标签的信息,请查看AxisLabels.ExactDateTime。
当频繁的修改坐标轴标签时,请记住TeeChart会根据AxisLabels.Separation属性的设置来避免标签的重叠。这意味着如果该标签被修改的频率高于标签所能接受的,那么TeeChart将为它分配最合适的那一个。 修改标签的角度和标签的separation两个属性可以帮助您找到最适合您的标签。请查看标签页以及AxisLabels.Angle属性。
标题
标题放置在Axis 页的Titles部分,您可以修改轴的标题文本以及文本的字体和阴影属性。标题文本的角度和大小都可以被指定。请在运行时查看AxisTitle类。
标签
从标签属性的摘要查看AxisLabels类。
当频繁的修改坐标轴标签,请记住TeeChart会根据AxisLabels.Separation属性的设置来避免标签重叠的部分。这意味着如果该标签被修改的频率高于标签所能接受的,那么TeeChart将为它分配最合适的那一个。 修改标签的角度和标签的separation两个属性可以帮组您找到最适合您的标签。请查看AxisLabels.Angle属性。
您可以将所有的标准数字和日期格式应用于坐标轴标签。在Axis页上,标签部分含有“Values format”域, 如果您的数据是日期型的,那么您可以将日期域的名字修改为“Date time format”。在运行时使用下面的代码:
日期型数据
坐标轴标签在显示时可以用多行文本来代替单行文本。使用LineSeparator character ()进行换行:
例如
日期型标签示例:
下面的代码将显示一个拥有两行文本的底轴标签,第一行显示月份和日期,第二行显示年份:
Feb-28 Mar-1 ..
2003 2003 ..
设置AxisLabels.MultiLine属性为True的时候,标签文本会在遇到空格时自动将文本换行,即将标签分成了两行:
'mm/dd'为第一行
'hh:mm'为第二行
在运行时,您同样可以在OnGetAxisLabel事件中通过编程实现对标签的分行:
在上面的例子中,“TeeSplitInLines”过程将标签文本中所有的空格都转换成行的分隔符(返回)。
坐标轴的AxisLabels.Angle属性同样也可被用于多行坐标轴标签。
可通过坐标轴事件使用标签控件的更多功能。这些事件允许您激活/停用/更改任何坐标轴标签。下面的示例将在该点索引值前面输入文本短语来修改每个标签:
查看坐标轴事件 的部分可以获取更多关于使用坐标轴事件来定制坐标轴标签的信息。
通过下面的方式设定一个标准的对数标签:
标签会根据对数的基数(默认10)而设置,因此在此例中显示的是1,10,100,1000,10000的标签。
刻度标记和分刻度
这里包含了3种刻度标记和2种网格。您可以修改刻度标记的长度,宽度,颜色以及网格类型。您可以通过“Ticks”标签修改刻度标记,它们相关联的网格和内部刻度标记;你还可以通过“Minor”标签修改分刻度标记和相关联的网格。新的TeeChart Pro 5版本可以改变刻度标记和网格样式,其宽度大于1(默认)。
坐标轴位置
坐标轴有一个属性可以对每个坐标轴的位置进行修改。在这个例子中,坐标轴移动了图表总宽度的50%,因此它在图表的中心位置进行显示:
附加坐标轴
复制坐标轴
TeeChart提供了5种与数据序列相关联的坐标轴:左边,顶部,底部,右边和纵深。当您向图表添加一个新的数据序列时,您需要定义该数据序列和哪种类型的坐标轴相关联(在总体页上选择数据序列标签)。通过坐标轴的Customdraw方法,您可以复用图表上的任何地方前4个坐标轴中的任何一个(或全部)。请注意,这个方法只是复制了已经存在的坐标轴,并没有添加一个新的自定义数据序列。查看下个章节(自定义多坐标轴)获取更多信息。
例如:
上面的实例代码所产生的效果如下图所示:
在这个例子中,TeeChart将在您的图表中心绘制新坐标轴,一个水平坐标轴,一个垂直坐标轴。当您滚动图表时 (使用鼠标右键拖拽),新的垂直坐标轴将始终保持在图表中心,新的水平坐标轴将上升和垂直滚动。新的坐标轴是默认坐标轴的精确副本。
自定义多坐标轴
连同PositionPercent和stretching 属性,它不可能有浮动在图表上任意点的无限坐标轴。坐标轴的滚动,缩放和命中检测都使用用户自己创建的坐标轴。您既可以在设计时通过TeeChart编辑器来创建附加的坐标轴,也可以在运行时添加一些代码来创建附加的坐标轴:
在设计时TeeChart为您提供了创建自定义坐标轴的功能,而且它们能够以TeeChart的目标文件格式进行保存。 要做到这一点,首先打开图表编辑器并在Axis页选择“+”按钮来添加一个自定义坐标轴。在确保你已经拥有新自定义坐标轴后,选择Position标签,此页上的水平复选框允许你定义新的自定义坐标轴,它们可以是水平坐标轴或不选择该复选框让其默认为垂直坐标轴。本页面的其余部分和Axis页的其他标签可以像前面介绍的那样用来改变自定义坐标轴的刻度,增量,标题,标签,刻度标记,分刻度和位置。为了使新自定义坐标轴能够和数据序列相关联,您需要进入Series标签的General页,并通过其中的“Horizontal Axis”和“Vertical Axis”下拉列表框定义自定义坐标轴的具体位置,但是这需要根据先前定义新自定义坐标轴的水平或者垂直方向来决定。
以上代码所产生的效果如下图所示:
所有操作是没有任何限制的!我们强烈建议您一定要谨慎使用自定义坐标轴,因为它很容易使用新的坐标轴来填充屏幕从而失去了您最希望跟踪管理的那个坐标轴!
坐标轴事件
坐标轴事件在运行时可以灵活地修改坐标轴标签并且可以通过点击坐标轴来增强当前用户的交互性。
OnClickAxis
查看OnClickAxis事件。
例如:
OnGetAxisLabel
用来修改坐标轴的标签。查看OnGetAxisLabel事件。
例子:
OnGetNextAxisLabel
它可用来判断显示哪个坐标轴标签。查看OnGetNextAxisLabel事件。 你应该使用e.Stop的Bool属性来包含/排除坐标轴标签。
例如:
联系我们
© 2002-2009 Steema Software SL. 版权所有
教程4 - 坐标轴控件
教程4 - 坐标轴控件
TeeChart Pro会自动为您定义所有坐标轴的标签,它们具有高度的灵活性可适应您任何特定的要求。TeeChart Pro提供了真正的多种坐标轴。在设计或运行时这些内容是可见的,另外它还提供了很多功能并在定义坐标轴时具有高度的灵活性。请参见本教程的各个章节以获得更多信息。内容
坐标轴控件 - 关键区域刻度
增量
标题
标签
刻度标记
坐标轴位置
附加坐标轴
复制坐标轴
多种坐标轴
坐标轴事件
OnClickAxis
OnGetAxisLabel
OnGetNextAxisLabel
坐标轴控件 - 关键区域
刻度当你添加数据序列到您的图表时,坐标轴的刻度会自动进行设置。您可在设计时或运行时通过坐标轴的属性来修改它们。
非日期型数据
当添加一个新的数据序列时,在TeeChart编辑器Axis页的Scales部分将显示自动选择和其他灰色的选择。 所有值均为数字。
日期型数据
在一个数据序列上设置一个日期型数据序列为True(该轴)的时候 -> 全部的页面,在TeeChart编辑器轴页的刻度部分将显示自动选择和其他灰色输出。所有值均为日期型。
自动选择最佳的坐标轴刻度范围将会非常适合您的数据。如果您关闭自动选择,那么刻度的部分将变成不可选择项,这时您可以改变坐标轴的值。最重要的是,请您记住在当前页左边的列表框中选择您所想要进行设置的坐标轴。
在设计时使用TeeChart编辑器添加一个线型数据序列到您的图表,然后用下面的代码添加一个命令按钮:
[C#.Net] Random rnd = new Random(); for(int i = 0; i <= 40; ++i) line1.Add(Convert.ToDouble(i),rnd.Next(100),Color.Red); [VB.Net] Dim i As Integer For i = 0 To 40 Line1.Add(Convert.ToDouble(i), Rnd() * 100, Color.Red) Next i
运行按钮中的代码将用40个随机值产生一个线型数据序列。 在设计时转到TeeChart编辑器。在Axis页的底轴刻度部分,将Automatic选项设为“off”,现在您就可以配置坐标轴刻度的最大和最小值。再次运行该代码将显示您为坐标轴设定的值。用鼠标的右键您可以滚动查看到剩余的值。
Setting axis scales by code
使用下面的代码您可以在运行时修改最大和最小值:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Automatic = false; bottomAxis.Maximum = 36; bottomAxis.Minimum = 5; [VB.Net] With TChart1.Axes.Bottom .Automatic = False .Maximum = 36 .Minimum = 5 End With
你可以分别设置坐标轴刻度最大和最小值的自动化属性。例如:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.AutomaticMaximum = true; bottomAxis.AutomaticMinimum = false; bottomAxis.Minimum = 5; [VB.Net] With TChart1.Axes.Bottom .AutomaticMaximum = True .AutomaticMinimum = False .Minimum = 5 End With
增量
您可以定制坐标轴的间隔。从Axis页刻度部分选择增量组合框并输入您想要的增量值。您也可以在运行时通过以下代码修改这个值:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Increment = 20; [VB.Net] With TChart1.Axes.Bottom .Increment = 20 End With
Datetime data
如果您是日期型数据(您可以通过总体页的数据序列标签设置您的数据序列为日期型),转到Chart标签->Axis页,刻度部分将显示日期范围。从增量组合框所示增量的范围选择并添加一些示例数据:
[C#.Net] Random rnd = new Random(); DateTime today = DateTime.Today; TimeSpan oneDay = TimeSpan.FromDays(1); line1.XValues.DateTime = true; for(int i = 1; i <= 25; ++i) line1.Add(today,rnd.Next(100),Color.Red); today += oneDay; [VB.Net] Dim i As Integer Dim Today As DateTime = DateTime.Today Dim OneDay As TimeSpan = TimeSpan.FromDays(1) Line1.XValues.DateTime = True For i = 1 To 25 Line1.Add(Today, Rnd() * 100, Color.Red) Today = Today.Add(OneDay) Next
在运行时修改增量值:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoDays); [VB.Net] With TChart1.Axes.Bottom .Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoDays) End With
了解更多有关日期坐标轴标签的信息,请查看AxisLabels.ExactDateTime。
Note
当频繁的修改坐标轴标签时,请记住TeeChart会根据AxisLabels.Separation属性的设置来避免标签的重叠。这意味着如果该标签被修改的频率高于标签所能接受的,那么TeeChart将为它分配最合适的那一个。 修改标签的角度和标签的separation两个属性可以帮助您找到最适合您的标签。请查看标签页以及AxisLabels.Angle属性。
标题
标题放置在Axis 页的Titles部分,您可以修改轴的标题文本以及文本的字体和阴影属性。标题文本的角度和大小都可以被指定。请在运行时查看AxisTitle类。
标签
从标签属性的摘要查看AxisLabels类。
Note
当频繁的修改坐标轴标签,请记住TeeChart会根据AxisLabels.Separation属性的设置来避免标签重叠的部分。这意味着如果该标签被修改的频率高于标签所能接受的,那么TeeChart将为它分配最合适的那一个。 修改标签的角度和标签的separation两个属性可以帮组您找到最适合您的标签。请查看AxisLabels.Angle属性。
Label formats
您可以将所有的标准数字和日期格式应用于坐标轴标签。在Axis页上,标签部分含有“Values format”域, 如果您的数据是日期型的,那么您可以将日期域的名字修改为“Date time format”。在运行时使用下面的代码:
[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 character ()进行换行:
例如
[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
日期型标签示例:
下面的代码将显示一个拥有两行文本的底轴标签,第一行显示月份和日期,第二行显示年份:
Feb-28 Mar-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”过程将标签文本中所有的空格都转换成行的分隔符(返回)。
坐标轴的AxisLabels.Angle属性同样也可被用于多行坐标轴标签。
Customising Axis labels
可通过坐标轴事件使用标签控件的更多功能。这些事件允许您激活/停用/更改任何坐标轴标签。下面的示例将在该点索引值前面输入文本短语来修改每个标签:
[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
查看坐标轴事件 的部分可以获取更多关于使用坐标轴事件来定制坐标轴标签的信息。
Logarithmic Labels
通过下面的方式设定一个标准的对数标签:
[C#.Net] private void button1_Click(object sender, System.EventArgs e) Random rnd = new Random(); Steema.TeeChart.Axis leftAxis = tChart1.Axes.Left; tChart1.Aspect.View3D = false; bar1.Marks.Visible = false; for(int i = 0; i <= 100; ++i) bar1.Add(rnd.Next(100) * i); leftAxis.LogarithmicBase = 10; leftAxis.Logarithmic = true; leftAxis.SetMinMax(0, 10000); leftAxis.Labels.ValueFormat = "#e+0"; //exponential format [VB.Net] Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer TChart1.Aspect.View3D = False Bar1.Marks.Visible = False For i = 0 To 10000 Step 100 Bar1.Add(Rnd() * i) Next With TChart1.Axes.Left .LogarithmicBase = 10 .Logarithmic = True .SetMinMax(0, 10000) .Labels.ValueFormat = "#e+0" ' exponential format End With End Sub
标签会根据对数的基数(默认10)而设置,因此在此例中显示的是1,10,100,1000,10000的标签。
刻度标记和分刻度
这里包含了3种刻度标记和2种网格。您可以修改刻度标记的长度,宽度,颜色以及网格类型。您可以通过“Ticks”标签修改刻度标记,它们相关联的网格和内部刻度标记;你还可以通过“Minor”标签修改分刻度标记和相关联的网格。新的TeeChart Pro 5版本可以改变刻度标记和网格样式,其宽度大于1(默认)。
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Ticks.Length = 7; bottomAxis.Ticks.Color = Color.Green; bottomAxis.MinorTickCount = 10; [VB.Net] With TChart1.Axes.Bottom .Ticks.Length = 7 .Ticks.Color = Color.Green .MinorTickCount = 10 End With
坐标轴位置
坐标轴有一个属性可以对每个坐标轴的位置进行修改。在这个例子中,坐标轴移动了图表总宽度的50%,因此它在图表的中心位置进行显示:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.PositionUnits = PositionUnits.Percent; bottomAxis. RelativePosition = 50 [VB.Net] With TChart1.Axes.Bottom .PositionUnits = PositionUnits.Percent .RelativePosition = 50 End With
附加坐标轴
复制坐标轴TeeChart提供了5种与数据序列相关联的坐标轴:左边,顶部,底部,右边和纵深。当您向图表添加一个新的数据序列时,您需要定义该数据序列和哪种类型的坐标轴相关联(在总体页上选择数据序列标签)。通过坐标轴的Customdraw方法,您可以复用图表上的任何地方前4个坐标轴中的任何一个(或全部)。请注意,这个方法只是复制了已经存在的坐标轴,并没有添加一个新的自定义数据序列。查看下个章节(自定义多坐标轴)获取更多信息。
例如:
[C#.Net] private void Form1_Load(object sender, System.EventArgs e) Random Rnd = new Random(); tChart1.Aspect.View3D = false; tChart1.Panel.Gradient.Visible = true; for(int t = 0; t <= 20; ++t) line1.Add(t, ((Rnd.Next(100)) + 1) - ((Rnd.Next(70)) + 1), Color.Red); private void line1_BeforeDrawValues(object sender, Steema.TeeChart.Drawing.Graphics3D g) int posAxis = 0; if(tChart1.Axes.Left.Maximum > 0) tChart1.Axes.Left.Draw(g.ChartXCenter - 10,g.ChartXCenter - 20,g.ChartXCenter,true); posAxis = tChart1.Axes.Left.CalcYPosValue(10); tChart1.Axes.Bottom.Draw(posAxis + 10, posAxis + 40, posAxis, true); [VB.Net] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim t As Integer TChart1.Aspect.View3D = False TChart1.Panel.Gradient.Visible = True For t = 0 To 20 Line1.Add(t, ((Rnd() * 100) + 1) - ((Rnd() * 70) + 1), Color.Red) Next End Sub Private Sub Line1_BeforeDrawValues(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles Line1.BeforeDrawValues Dim posAxis As Integer If TChart1.Axes.Left.Maximum > 0 Then TChart1.Axes.Left.Draw(g.ChartXCenter - 10, g.ChartXCenter - 20, g.ChartXCenter, True) posAxis = TChart1.Axes.Left.CalcYPosValue(10) TChart1.Axes.Bottom.Draw(posAxis + 10, posAxis + 40, posAxis, True) End If End Sub
上面的实例代码所产生的效果如下图所示:
Custom axes
在这个例子中,TeeChart将在您的图表中心绘制新坐标轴,一个水平坐标轴,一个垂直坐标轴。当您滚动图表时 (使用鼠标右键拖拽),新的垂直坐标轴将始终保持在图表中心,新的水平坐标轴将上升和垂直滚动。新的坐标轴是默认坐标轴的精确副本。
自定义多坐标轴
连同PositionPercent和stretching 属性,它不可能有浮动在图表上任意点的无限坐标轴。坐标轴的滚动,缩放和命中检测都使用用户自己创建的坐标轴。您既可以在设计时通过TeeChart编辑器来创建附加的坐标轴,也可以在运行时添加一些代码来创建附加的坐标轴:
Via the Chart Editor
在设计时TeeChart为您提供了创建自定义坐标轴的功能,而且它们能够以TeeChart的目标文件格式进行保存。 要做到这一点,首先打开图表编辑器并在Axis页选择“+”按钮来添加一个自定义坐标轴。在确保你已经拥有新自定义坐标轴后,选择Position标签,此页上的水平复选框允许你定义新的自定义坐标轴,它们可以是水平坐标轴或不选择该复选框让其默认为垂直坐标轴。本页面的其余部分和Axis页的其他标签可以像前面介绍的那样用来改变自定义坐标轴的刻度,增量,标题,标签,刻度标记,分刻度和位置。为了使新自定义坐标轴能够和数据序列相关联,您需要进入Series标签的General页,并通过其中的“Horizontal Axis”和“Vertical Axis”下拉列表框定义自定义坐标轴的具体位置,但是这需要根据先前定义新自定义坐标轴的水平或者垂直方向来决定。
Via Code [C#.Net] private void Form1_Load(object sender, System.EventArgs e) Line line1 = new Line(); Line line2 = new Line(); tChart1.Aspect.View3D = false; tChart1.Panel.Gradient.Visible = true; tChart1.Header.Text = "TeeChart Multiple Axes"; tChart1.Series.Add(line1); tChart1.Series.Add(line2); for(int t = 0; t <= 10; ++t) line1.Add(Convert.ToDouble(t), Convert.ToDouble(10 + t), Color.Red); if(t > 1) line2.Add(Convert.ToDouble(t), Convert.ToDouble(t), Color.Green); Axis leftAxis = tChart1.Axes.Left; leftAxis.StartPosition = 0; leftAxis.EndPosition = 50; leftAxis.AxisPen.Color = Color.Red; leftAxis.Title.Font.Color = Color.Red; leftAxis.Title.Font.Bold = true; leftAxis.Title.Text = "1st Left Axis"; // You are able to then position the new Axis in overall relation to the Chart // by using the StartPosition and EndPosition properties. // // StartPosition=50 // EndPosition=100 // // These figures are expressed as percentages of the Chart Rectangle with 0 (zero) // (in the case of a vertical Axis) being Top. These properties can be applied to // the Standard Axes to create completely partitioned 'SubCharts' within the Chart. Axis axis1 = new Axis(false, false, tChart1.Chart); tChart1.Axes.Custom.Add(axis1); line2.CustomVertAxis = axis1; axis1.StartPosition = 50; axis1.EndPosition = 100; axis1.AxisPen.Color = Color.Green; axis1.Title.Font.Color = Color.Green; axis1.Title.Font.Bold = true; axis1.Title.Text = "Extra Axis"; axis1.PositionUnits= PositionUnits.Percent; axis1.RelativePosition = 20; [VB.Net] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Line1 As New Steema.TeeChart.Styles.Line() Dim Line2 As New Steema.TeeChart.Styles.Line() Dim t As Integer TChart1.Aspect.View3D = False TChart1.Panel.Gradient.Visible = True TChart1.Header.Text = "TeeChart Multiple Axes" TChart1.Series.Add(Line1) TChart1.Series.Add(Line2) For t = 0 To 10 Line1.Add(t, 10 + t, Color.Red) If (t > 1) Then Line2.Add(t, t, Color.Green) End If Next With TChart1.Axes.Left .StartPosition = 0 .EndPosition = 50 .AxisPen.Color = Color.Red .Title.Font.Color = Color.Red .Title.Font.Bold = True .Title.Text = "1st Left Axis" End With 'You are able to then position the new Axis in overall relation to the Chart 'by using the StartPosition and EndPosition properties. ' StartPosition = 50 ' EndPosition = 100 'These figures are expressed as percentages of the Chart Rectangle with 0 (zero) '(in the case of a vertical Axis) being Top. These properties can be applied to 'the Standard Axes to create completely partitioned 'SubCharts' within the Chart. Dim Axis1 As New Steema.TeeChart.Axis(False, False, TChart1.Chart) TChart1.Axes.Custom.Add(Axis1) Line2.CustomVertAxis = Axis1 Axis1.StartPosition = 50 Axis1.EndPosition = 100 Axis1.AxisPen.Color = Color.Green Axis1.Title.Font.Color = Color.Green Axis1.Title.Font.Bold = True Axis1.Title.Text = "Extra Axis" Axis1.PositionUnits.= PositionUnits.Percent; Axis1.RelativePosition = 20 End Sub
以上代码所产生的效果如下图所示:
Multiple axes
所有操作是没有任何限制的!我们强烈建议您一定要谨慎使用自定义坐标轴,因为它很容易使用新的坐标轴来填充屏幕从而失去了您最希望跟踪管理的那个坐标轴!
坐标轴事件
坐标轴事件在运行时可以灵活地修改坐标轴标签并且可以通过点击坐标轴来增强当前用户的交互性。OnClickAxis
查看OnClickAxis事件。例如:
[C#.Net] private void tChart1_ClickAxis(object sender, System.Windows.Forms.MouseEventArgs e) if(((Steema.TeeChart.Axis)sender).Equals(tChart1.Axes.Bottom)) MessageBox.Show("Clicked Bottom Axis at: " + line1.XScreenToValue(e.X)); [VB.Net] Private Sub TChart1_ClickAxis(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.ClickAxis If CType(sender, Steema.TeeChart.Axis) Is TChart1.Axes.Bottom Then MsgBox("Clicked Bottom Axis at: " & Line1.XScreenToValue(e.X)) End If End Sub
OnGetAxisLabel
用来修改坐标轴的标签。查看OnGetAxisLabel事件。例子:
[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
OnGetNextAxisLabel
它可用来判断显示哪个坐标轴标签。查看OnGetNextAxisLabel事件。 你应该使用e.Stop的Bool属性来包含/排除坐标轴标签。
例如:
[C#.Net] private void Form1_Load(object sender, System.EventArgs e) line1.FillSampleValues(20); private void tChart1_GetNextAxisLabel(object sender, Steema.TeeChart.TChart.GetNextAxisLabelEventArgs e) if(((Steema.TeeChart.Axis)sender).Equals(tChart1.Axes.Bottom)) e.Stop = false; switch(e.LabelIndex) case 0: e.LabelValue = 5; break; case 1: e.LabelValue = 13; break; case 2: e.LabelValue = 19; break; default: e.Stop = true; break; [VB.Net] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Line1.FillSampleValues(20) End Sub Private Sub TChart1_GetNextAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.TChart.GetNextAxisLabelEventArgs) Handles TChart1.GetNextAxisLabel If CType(sender, Steema.TeeChart.Axis) Is TChart1.Axes.Bottom Then e.Stop = False Select Case e.LabelIndex Case 0 : e.LabelValue = 5 Case 1 : e.LabelValue = 13 Case 2 : e.LabelValue = 19 Case Else : e.Stop = True End Select End If End Sub
联系我们
© 2002-2009 Steema Software SL. 版权所有
相关文章推荐
- TeeChart Pro .Net 教程 ---教程01 - 入门
- TeeChart Pro .Net 教程---教程2 - 图表显示属性
- TeeChart Pro .Net 教程 --教程3 - 图表页
- vb.net 教程 3-4 窗体编程 公共控件9 ListView 6
- 工控仪表控件Iocomp ActiveX系列教程: 插入ASP.NET页面
- Infragistics系列控件中文教程 Infragistics ASP.NET控件用法总结
- TeeChart for .NET中文版教程大全
- 庖丁解牛:纵向切入Asp.net 3.5控件和组件开发技术系列—教程
- 经典正则表达式 - 清清月儿 .NET万花筒 Asp.net技术 Asp.net教程 Asp.net源码 Asp.net基础 Asp.net控件 Asp.net入门 - CSDNBlog
- vb.net 教程 3-11 窗体控件综合编程 2-2
- AjaxControlToolkit 微软出的ajax.net 工具使用教程五 ConfirmButtonExtender(确认)控件的使用
- AjaxControlToolkit 微软出的ajax.net 工具使用教程二十 AutoCompleteExtender(自动提示)控件的使用
- ASP.NET AJAX服务器端控件官方视频教程 下载--英文
- ASP.NETAdRotator控件使用 - asp.net 教程-
- vb.net 教程 3-13 动态创建控件1
- Word控件Spire.Doc 教程:在C#,VB.NET的Word中检索所有TextRanges样式名称
- [翻译]Scott Mitchell 的ASP.NET 2.0数据教程之四十七:使用SqlDataSource控件查询数据
- 从DataView中生成Excel报表的方案(C#) - 清清月儿 .NET万花筒 Asp.net技术 Asp.net教程 Asp.net源码 Asp.net基础 Asp.net控件 Asp.net入门 - CSDNBlog
- vb.net 教程 3-4 窗体编程 公共控件7 DateTimePicker & MonthCalendar
- 流程图控件FlowChart.NET使用教程:复合命令