翻譯|使用教程|編輯:楊鵬連|2021-06-08 11:33:16.940|閱讀 269 次
概述:TeeChart Pro會自動為你定義所有的軸標記,并提供足夠的靈活性來定制你可能有的任何具體要求。更多信息請參見本教程中的章節。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TeeChart for .NET是優秀的工業4.0 WinForm圖表控件,官方獨家授權漢化,集功能全面、性能穩定、價格實惠等優勢于一體。TeeChart for .NET 中文版還可讓您在使用和學習上沒有任何語言障礙,至少可以節省30%的開發時間。
TeeChart Pro會自動為你定義所有的軸標記,并提供足夠的靈活性來定制你可能有的任何具體要求。TeeChart Pro提供真正的多軸。這些都可以在設計或運行時使用,為軸的定義提供了無數的可能性和靈活性。更多信息請參見本教程中的章節。
軸控制 - 關鍵領域
尺度
當你將系列數據添加到圖表中時,軸的刻度會自動設置。你可以在設計時或在運行時通過使用軸的屬性來改變默認值。
當一個系列在系列->常規頁面上將日期時間設置為真(對于該軸),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編輯器。在 "軸 "頁面的 "底軸刻度 "部分將自動 "關閉"。你現在可以為軸刻度配置最大值和最小值。再次運行代碼時,將根據你為軸配置的值來顯示數值。使用鼠標的右鍵,你可以滾動查看剩余的值。
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遞增
你可以定制軸的間隔。從軸頁面的Scales部分選擇Desired Increment組合框,并添加你需要的增量。你可以在運行時通過代碼改變這一點。
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Increment = 20; [VB.Net] With TChart1.Axes.Bottom .Increment = 20 End With日期時間數據
如果你的數據是數據時間(你可以通過進入系列,常規頁面為你的系列設置數據為數據時間),Chart->Axis頁面,scales部分將顯示數據時間范圍。從 "期望的增量 "組合框中選擇增量,并添加一些樣本數據。
[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屬性以了解更多關于日期軸標記的信息。
標題
標題是在軸頁的標題部分設置的。你可以改變軸的標題文本及其字體和陰影屬性。標題文本的角度和大小也可以被指定。關于運行時間,請看 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多線標簽
[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 = 10DateTime標簽的例子
[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將自動在有空格的地方分割標簽,有效地將標簽分成兩部分。
在運行時,你總是可以使用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屬性也可以用于多行軸標簽。
定制軸標簽
進一步的標簽控制可以通過使用Axis事件獲得。這些事件允許你激活/停用/改變任何單獨的軸標簽。下面的例子修改了每個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關于用軸事件定制標簽的更多信息,請參見題為軸事件的章節。
對數標簽
正常的對數標簽可以通過以下方式設置。
[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處設置標簽。
Ticks and Minor
[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個與數據系列相關的軸。左、頂、底、右和深度。當你在圖表中添加一個新的系列時,你可以定義該系列應該與哪個軸相關(進入系列標簽,常規頁面)。您可以通過使用Axis 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上面的示例代碼將產生下面的圖像。
多個自定義軸
與PositionPercent和拉伸屬性一起,可以在圖表的任何地方浮動無限的軸。滾動、縮放和坐標軸的檢測也適用于自定義創建的坐標軸。現在可以在設計時通過TeeChart編輯器和在運行時通過幾行代碼創建額外的軸。
通過圖表編輯器
通過代碼
[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上面的編碼例子
軸事件
軸事件提供了運行時的靈活性,以修改軸標簽,并在軸點擊時呈現用戶的互動性。
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 SubOnGetAxisLabel
可以用來修改軸的標簽。參見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 SubOnGetNextAxisLabel
可以用來決定哪些軸標簽應該被顯示。參見OnGetNextAxisLabel事件。你應該使用e.Stop布爾屬性來包括/排除軸標簽。
例子
[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
現TeeChart for .NET已加入在線訂購,現在搶購可立享優惠!
如果您對該圖表控件感興趣,歡迎加入圖表控件QQ交流群:740060302
關注慧聚IT微信公眾號???,了解產品的最新動態及最新資訊。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: