原創(chuàng)|使用教程|編輯:何家巧|2022-12-23 11:39:31.373|閱讀 240 次
概述:在TeeChar系列教程中,上一章我們主要講解了如何實(shí)現(xiàn)軸控制(中),今天我們繼續(xù)為大家講解實(shí)現(xiàn)軸控制的最后一部分。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
TeeChart for .NET是優(yōu)秀的工業(yè)4.0 WinForm圖表控件,官方獨(dú)家授權(quán)漢化,集功能全面、性能穩(wěn)定、價(jià)格實(shí)惠等優(yōu)勢(shì)于一體。TeeChart for .NET 中文版還可讓您在使用和學(xué)習(xí)上沒有任何語言障礙,至少可以節(jié)省30%的開發(fā)時(shí)間。
在TeeChar系列教程中,上一章我們主要講解了如何實(shí)現(xiàn)軸控制(中),今天我們繼續(xù)為大家講解“實(shí)現(xiàn)軸控制的最后一部分”。
TeeChart for .NET技術(shù)交流QQ群:740060302 ,歡迎加入
對(duì)數(shù)標(biāo)簽
正常的對(duì)數(shù)標(biāo)簽可按以下方式設(shè)置。
[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
標(biāo)簽將根據(jù)對(duì)數(shù)基數(shù)(默認(rèn)為10)進(jìn)行設(shè)置,因此,在這種情況下,標(biāo)簽將被設(shè)置為1、10、100、1000、10000。
Ticks and Minor
有3種刻度線類型和2種網(wǎng)格類型。你可以改變每個(gè)刻度線和網(wǎng)格類型的長度、寬度和顏色。可以通過 "Ticks "選項(xiàng)卡對(duì)Ticks、其相關(guān)的Grid和Inner Ticks進(jìn)行更改;對(duì)Minor Ticks和其相關(guān)的Grid的更改可以通過 "Minor "選項(xiàng)卡進(jìn)行。TeeChart Pro第5版的新功能是可以改變寬度大于1(默認(rèn))的Ticks和Grid的樣式。
[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
軸的位置
軸有一個(gè)屬性可以修改每個(gè)軸的位置。在這個(gè)例子中,軸被移動(dòng)到圖表總寬度的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
附加軸
復(fù)制坐標(biāo)軸
TeeChart提供5個(gè)與數(shù)據(jù)系列相關(guān)的軸。左側(cè)、頂部、底部、右側(cè)和深度。當(dāng)你在圖表中添加一個(gè)新的系列時(shí),你可以定義該系列應(yīng)該與哪個(gè)軸相關(guān)(進(jìn)入系列標(biāo)簽,常規(guī)頁面)。您可以通過使用Axis Customdraw方法在圖表的任何地方重復(fù)前4個(gè)軸的任何一個(gè)(或全部)。請(qǐng)注意,這種方法是對(duì)你的軸進(jìn)行復(fù)制,而不是添加一個(gè)新的自定義軸。更多信息請(qǐng)參見下一節(jié) "多個(gè)自定義軸"。
舉例:
[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
上面的示例代碼將產(chǎn)生以下圖像。
自定義坐標(biāo)軸
在這個(gè)例子中,TeeChart將繪制新的坐標(biāo)軸,一個(gè)水平軸和一個(gè)垂直軸位于圖表的中心。當(dāng)你滾動(dòng)圖表時(shí)(用鼠標(biāo)右鍵拖動(dòng)),新的垂直軸將始終保持在圖表的中央,新的水平軸將隨著垂直滾動(dòng)上下移動(dòng)。新的坐標(biāo)軸是默認(rèn)坐標(biāo)軸的精確拷貝。
多個(gè)自定義軸
與PositionPercent和拉伸屬性一起,可以在圖表的任何地方浮動(dòng)無限的軸。滾動(dòng)、縮放和坐標(biāo)軸的檢測也適用于自定義創(chuàng)建的坐標(biāo)軸。現(xiàn)在可以在設(shè)計(jì)時(shí)通過TeeChart編輯器和在運(yùn)行時(shí)通過幾行代碼創(chuàng)建額外的軸。
通過圖表編輯器
TeeChart為您提供了在設(shè)計(jì)時(shí)創(chuàng)建自定義坐標(biāo)軸的功能,使它們能夠以TeeChart的tee文件格式保存。要做到這一點(diǎn),打開圖表編輯器,點(diǎn)擊軸選項(xiàng)卡,然后選擇 "+"按鈕來添加一個(gè)自定義軸。然后選擇 "位置 "選項(xiàng)卡,確保你的新自定義軸被高亮顯示。這個(gè)頁面上的水平復(fù)選框允許你將新的自定義軸定義為水平軸,或者將其作為默認(rèn)的垂直軸。本頁的其余部分和軸頁的其他選項(xiàng)卡可以用來改變自定義軸的尺度、增量、標(biāo)題、標(biāo)簽、刻度、小刻度和位置,如上所述。要將這個(gè)新的自定義軸與你想要的數(shù)據(jù)系列聯(lián)系起來,請(qǐng)選擇系列選項(xiàng)卡并進(jìn)入常規(guī)頁面,其中的下拉組合框 "水平軸 "和 "垂直軸 "將使你能夠選擇新的自定義軸,這取決于你之前將其定義為垂直或水平。
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
上面的編碼例子
...將顯示以下圖表。
多軸
選項(xiàng)是無限的! 我們建議在使用自定義軸時(shí)要謹(jǐn)慎,因?yàn)楹苋菀组_始用新的軸來填滿屏幕,并失去了你希望管理的軸的蹤跡!
軸事件
軸事件提供了運(yùn)行時(shí)的靈活性,以修改軸標(biāo)簽,并在軸點(diǎn)擊時(shí)呈現(xiàn)用戶的互動(dòng)性。
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
可以用來修改軸的標(biāo)簽。參見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
可以用來決定哪些軸的標(biāo)簽應(yīng)該被顯示。參見OnGetNextAxisLabel事件。你應(yīng)該使用e.Stop布爾屬性來包括/排除軸標(biāo)簽。
例如:
[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系列教程中的關(guān)于“軸控制”介紹的全部內(nèi)容了,點(diǎn)擊查看完整詳情。
如果您想了解TeeChart for .NET價(jià)格,歡迎咨詢
TeeChart for .NET 是優(yōu)秀的工業(yè)4.0 WinForm圖表控件,官方獨(dú)家授權(quán)漢化,集功能全面、性能穩(wěn)定、價(jià)格實(shí)惠等優(yōu)勢(shì)于一體。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn