翻譯|使用教程|編輯:楊鵬連|2021-06-21 11:47:14.927|閱讀 229 次
概述:作為TeeChart類型庫結構的一個小背景,這里是對系列類和接口的一個解釋。更多信息請參見本教程中的章節。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TeeChart for .NET是優秀的工業4.0 WinForm圖表控件,官方獨家授權漢化,集功能全面、性能穩定、價格實惠等優勢于一體。TeeChart for .NET 中文版還可讓您在使用和學習上沒有任何語言障礙,至少可以節省30%的開發時間。
系列類型
TChart Series 類是所有 Series 類型的共同祖先。當使用TeeChart在線幫助獲得關于任何系列類型的幫助時,請遵循位于繼承類型列表中的系列類的鏈接,然后點擊系列成員,那里將包括所有繼承的屬性和方法的列表。
系列類的結構
作為TeeChart類型庫結構的一個小背景,這里是對系列類和接口的一個解釋。下圖顯示了TeeChart系列類之間的關系。所有的類都來自于通用的 "系列 "類,因此共享 "系列 "屬性和方法。有幾個抽象類派生自Series(Custom3DSeries、CustomBarSeries和CircledSeries),這些類以灰色顯示,它們的接口不能直接用于編程,它們的特性被它們的后代Series類型所繼承。所有派生的系列(橙色)都可以在TeeChart圖庫中訪問,以納入你的圖表中。以這種方式派生的TeeChart系列,允許通過一個共同的索引結構對繼承的屬性和方法進行可編程的訪問(見本節后面的示例代碼)。
使用TChart編輯器在設計時添加系列更容易,但你也可以在運行時創建和添加新的和不同的系列類型到同一個TChart中。
[C#] //Add a series at runtime private void button1_Click(object sender, System.EventArgs e) { Steema.TeeChart.Styles.Area tmpAreaSeries = new Steema.TeeChart.Styles.Area(tChart1.Chart); tmpAreaSeries.FillSampleValues(4); //Or //Steema.TeeChart.Styles.Area tmpAreaSeries = new Steema.TeeChart.Styles.Area(); //tChart1.Series.Add(tmpAreaSeries); //tmpAreaSeries.FillSampleValues(4); } [VB.Net] 'Add a series at runtime Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tmpAreaSeries As New Steema.TeeChart.Styles.Area(TChart1.Chart) tmpAreaSeries.FillSampleValues(4) 'Or 'Dim tmpAreaSeries As New Steema.TeeChart.Styles.Area() 'TChart1.Series.Add(tmpAreaSeries) 'tmpAreaSeries.FillSampleValues(4) End Sub所有AreaSeries的屬性和方法對新系列都是可用的,就像在設計時創建的任何系列一樣。
在同一個圖表中混合使用不同系列的例子是在一個圖表中添加Area (Series(0)), Bar (Series(1)) 和 Line (Series(2)) 系列到一個圖表中。所有這些都訪問一個共同的索引結構,即圖表的系列列表。與系列有關的工作可能看起來像下面這樣。
[C#] private void Form1_Load(object sender, System.EventArgs e) { //You could add the Series at runtime Steema.TeeChart.Styles.Area area1 = new Steema.TeeChart.Styles.Area(tChart1.Chart); Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart); Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart); //Use Series common properties tChart1.Series[0].FillSampleValues(10); tChart1.Series[1].FillSampleValues(10); tChart1.Series[2].FillSampleValues(10); tChart1.Series[1].Marks.Visible = false; tChart1.Series[2].Marks.Visible = false; //Modify Bar specific properties bar1.BarStyle = Steema.TeeChart.Styles.BarStyles.Pyramid; //Change Bar type bar1.Pen.Color = Color.Yellow; //Bar bounding lines colour //Modify Line specific properties line1.Stairs = true; //Set line to Stairs line1.LinePen.Color = Color.Blue; //LineSeries bounding lines colour //Modify Area specific properties area1.AreaBrush.Style = System.Drawing.Drawing2D.HatchStyle.Cross; //Area fill pattern } [VB.Net] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'You could add the Series at runtime Dim Area1 As New Steema.TeeChart.Styles.Area(TChart1.Chart) Dim Bar1 As New Steema.TeeChart.Styles.Bar(TChart1.Chart) Dim Line1 As New Steema.TeeChart.Styles.Line(TChart1.Chart) 'Use Series common properties TChart1.Series(0).FillSampleValues(10) TChart1.Series(1).FillSampleValues(10) TChart1.Series(2).FillSampleValues(10) TChart1.Series(1).Marks.Visible = False TChart1.Series(2).Marks.Visible = False 'Modify Bar specific properties Bar1.BarStyle = Steema.TeeChart.Styles.BarStyles.Pyramid 'Change Bar type Bar1.Pen.Color = Color.Yellow 'Bar bounding lines colour 'Modify Line specific properties Line1.Stairs = True 'Set line to Stairs Line1.LinePen.Color = Color.Blue 'LineSeries bounding lines colour 'Modify Area specific properties Area1.AreaBrush.Style = System.Drawing.Drawing2D.HatchStyle.Cross 'Area fill pattern End Sub選擇一個系列類型
為圖表選擇系列類型在很大程度上取決于你自己對圖表的要求。然而,在有些情況下,由于要繪制的變量數量,圖表的選擇可能取決于哪些系列類型支持輸入變量的數量。下表顯示了每種系列類型所允許的變量數量。
例子
使用條形系列類型
[C#] foreach(Steema.TeeChart.Styles.Series tSeries in tChart1.Series) {tSeries.Marks.Visible = false;} tChart1.Header.Text = "Production results"; bar1.Add(300,"Jan"); bar1.Add(325,"Feb"); bar1.Add(287,"Mar"); bar1.Title = "Product10"; bar2.Add(175,"Jan"); bar2.Add(223,"Feb"); bar2.Add(241,"Mar"); bar2.Title = "Product12"; bar3.Add(461,"Jan"); bar3.Add(470,"Feb"); bar3.Add(455,"Mar"); bar3.Title = "Product14"; [VB.Net] Dim TSeries As Steema.TeeChart.Styles.Series For Each TSeries In TChart1.Series TSeries.Marks.Visible = False Next TChart1.Header.Text = "Production results" Bar1.Add(300, "Jan") Bar1.Add(325, "Feb") Bar1.Add(287, "Mar") Bar1.Title = "Product10" Bar2.Add(175, "Jan") Bar2.Add(223, "Feb") Bar2.Add(241, "Mar") Bar2.Title = "Product12" Bar3.Add(461, "Jan") Bar3.Add(470, "Feb") Bar3.Add(455, "Mar") Bar3.Title = "Product14"或(按產品分組)
[C#] foreach(Steema.TeeChart.Styles.Series tSeries in tChart1.Series) {tSeries.Marks.Visible = false;} tChart1.Header.Text = "Production results"; bar1.Add(300,"Product10"); bar1.Add(175,"Product12"); bar1.Add(461,"Product14"); bar1.Title = "Jan"; bar2.Add(325,"Product10"); bar2.Add(223,"Product12"); bar2.Add(470,"Product14"); bar2.Title = "Feb"; bar3.Add(287,"Product10"); bar3.Add(241,"Product12"); bar3.Add(455,"Product14"); bar3.Title = "Mar"; [VB.Net] Dim TSeries As Steema.TeeChart.Styles.Series For Each TSeries In TChart1.Series TSeries.Marks.Visible = False Next TChart1.Header.Text = "Production results" Bar1.Add(300, "Product10") Bar1.Add(175, "Product12") Bar1.Add(461, "Product14") Bar1.Title = "Jan" Bar2.Add(325, "Product10") Bar2.Add(223, "Product12") Bar2.Add(470, "Product14") Bar2.Title = "Feb" Bar3.Add(287, "Product10") Bar3.Add(241, "Product12") Bar3.Add(455, "Product14") Bar3.Title = "Mar"我們在上面的表格中增加了新的數值(庫存)。
[C#] line1.Add(600,"Jan"); line1.Add(715,"Feb"); line1.Add(676,"Mar"); line1.Title = "Product10 Stock"; line1.Color = bar1.Color; line2.Add(245,"Jan"); line2.Add(270,"Feb"); line2.Add(315,"Mar"); line2.Title = "Product10 Stock"; line2.Color = bar2.Color; line3.Add(800,"Jan"); line3.Add(755,"Feb"); line3.Add(835,"Mar"); line3.Title = "Product10 Stock"; line3.Color = bar3.Color; [VB.Net] Line1.Add(600, "Jan") Line1.Add(715, "Feb") Line1.Add(676, "Mar") Line1.Title = "Product10 Stock" Line1.Color = Bar1.Color Line2.Add(245, "Jan") Line2.Add(270, "Feb") Line2.Add(315, "Mar") Line2.Title = "Product10 Stock" Line2.Color = Bar2.Color Line3.Add(800, "Jan") Line3.Add(755, "Feb") Line3.Add(835, "Mar") Line3.Title = "Product10 Stock" Line3.Color = Bar3.Color將數據添加到系列中
大多數系列類型(除ADO.NET數據源教程8和函數教程7外)都使用24種通用重載的添加方法來添加數據。但也有一些例外情況,見下表。
請注意,除了ShapeSeries之外,所有特定的系列添加方法都被自動添加為通用添加方法的進一步重載,因此可以從這里訪問(例如candleSeries1.Add(new DateTime(2002,11,27),100,400,200,300);)。
顏色
在添加點的時候,可以手動為其添加顏色
例子
[C#] bar1.Add(50, "Tomatoes",Color.Tomato)。 [VB.Net] Bar1.Add(50, "Tomatoes", Color.Tomato)另外,你可以讓TeeChart分配一個顏色。TeeChart將為每個新系列選擇最多19種獨特的、尚未使用的顏色,或者如果Series.ColorEach = True,則為每個新系列點選擇顏色。
[C#] Random rnd = new Random(); bar1.ColorEach = true; for(int i = 0; i < 19; ++i) { int higher = i + 65; char letter = (char) higher; bar1.Add(rnd.Next(100),letter.ToString()); } [VB.Net] Dim i As Integer Bar1.ColorEach = True For i = 0 To 19 Bar1.Add(Rnd() * 100, Chr(i + 65)) Next一個透明的顏色可以被添加到一個點上,以便為ValueList中的值保留一個空間,而不在圖表上顯示。
[C#] bar1.Add(45, "My Transparent Bar", Color.Transparent)。 [VB.Net] Bar1.Add(45, "My Transparent Bar", Color.Transparent)從系列中刪除數據點
使用Series.Delete從一個系列中刪除一個點。Series.Delete有兩個重載。
public Void Delete(System.Int32)刪除系列中的第n個點。
public Void Delete(System.Int32, System.Int32)從系列中的第n個點開始刪除若干個點。
[C#] bar1.Delete(7,2); (從系列的第8個點開始刪除兩個點(索引從0開始)) [VB.Net] Bar1.Delete(7,2) (刪除從第8個系列點開始的兩個點(索引從零開始))Series.Clear清除一個系列中的所有點。
將空點添加到系列中
Series.Add有三個重載,允許你向系列中添加一個空點。
添加一個新的空(透明)點。
public Int32 Add()
添加一個新的空點并指定文本。
public Int32 Add(System.String)
在指定的X值處添加一個新的空點,并指定文字。
public Int32 Add(System.Double, System.String)
上述第二個重載將在系列中添加一個空點,允許你為該點定義一個標簽,但在系列中的該點留下一個斷點。在線型系列的情況下,斷點前的最后一個點不會與斷點后的第一個點連接。
例子
[C#] line1.Add("Null Point")。 [VB.Net] Line1.Add("Null Point")請在TeeChart幫助文件中查找其他兩個重載,了解它們的使用實例。
在一個圖表上混合系列類型
TeeChart Pro提供了一個空的Chart Canvas作為數據系列的背景。這意味著沒有預定義的圖表類型。你可以定義你需要的圖表類型,作為你希望顯示的系列類型的混合。由于一些系列類型的特殊性,在一個圖表上將該系列類型與另一個系列類型混合在一起是不現實的。當你添加一個新的系列時,TeeChart會在圖表庫中把不合適的系列類型顯示為灰色,從而幫助你。對于你可以在一個圖表中放置的系列的數量沒有實際限制。
添加新系列
使用TeeChart編輯器(見教程1)或通過代碼添加一個系列。
例子
[C#] private void button1_Click(object sender, System.EventArgs e) { Bar bar1 = new Bar(tChart1.Chart); bar1.FillSampleValues(10); } [VB.Net] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Bar1 As New Steema.TeeChart.Styles.Bar(TChart1.Chart) Bar1.FillSampleValues(10) End Sub系列被添加到SeriesList中,可以通過Index, TChart1.Series(Index)訪問,第一個系列從0開始。TeeChart Pro為系列添加了一個默認的名稱(系列0,系列1,等等)。你可以使用Series.Title屬性修改該名稱。
為一個系列選擇軸
添加到圖表中的系列會自動將左軸和底軸作為其參考軸。你可以在圖表編輯器中通過選擇相關系列的系列常規頁來改變參考軸。有4個軸可用,頂部、左側、底部和右側。通過代碼,改變坐標軸看起來像這樣。
[C#] bar1.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right; bar1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top; [VB.Net] Bar1.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right Bar1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top每個軸可以關聯1個以上的系列。TeeChart將決定與軸相匹配的系列的最佳比例,但你可以自己改變軸的比例(見軸的教程)。可以添加額外的軸;它們將復制與前4個軸的對應部分相關的刻度(見教程中的額外軸)。
連接系列
你可以使用一個系列作為另一個系列的數據源。這可以在圖表編輯器中通過設置第二個系列的數據源來實現。進入 "系列 "標簽,數據源頁面。選擇 "函數 "作為數據源類型。會出現兩個列表框,可用系列和選定系列。選擇你希望用作當前系列的數據源的系列,然后在上面的組合框中,題為 "函數:",選擇 "平均 "作為函數類型,并點擊 "應用 "按鈕。請注意,任何系列,以這種方式,可以被定義為任何其他系列的函數,函數類型可以是函數組合框中的任何列表。要通過代碼做同樣的事情,請看下面。
[C#] Steema.TeeChart.Functions.Average1 = new Steema.TeeChart.Functions.Average()。 line1.Function = average1; line1.DataSource = bar1; bar1.FillSampleValues(10); line1.CheckDataSource()。 [VB.Net] Dim Average1 As New Steema.TeeChart.Functions.Average() Line1.Function = Average1 Line1.DataSource = Bar1 Bar1.FillSampleValues(10) Line1.CheckDataSource()關于如何使用TeeChart函數的更多信息,請參見教程7--使用函數工作。
改變系列順序
使用圖表編輯器,改變系列順序非常容易。進入編輯器的前頁,突出顯示你想移動的系列。使用右邊的箭頭按鈕,在系列順序中向上或向下移動系列。系列順序將決定該系列在圖表中相對于其他系列的相對顯示位置。將一個系列設置為 "Active=False "將從圖表中隱藏該系列,但保持其數據內容不變。
要通過代碼改變系列順序,請使用Series.Exchange。
[C#] tChart1.Series.Exchange(0, 1); //用Series(1)改變系列(0)的索引順序。 [VB.Net] TChart1.Series.Exchange(0, 1) '按照索引順序用Series(1)改變Series(0)。*注意。在交換系列后,系列的索引將被改變。因此,如果重新運行代碼,上面的這行代碼將永久地交換兩個系列'0'和'1',因為0變成了1,1變成了0。
系列值列表
TeeChart系列將它們的值存儲在一個Valuelist中,可通過ValueList類訪問和修改。
訪問系列值
你可以訪問列表中的任何值。
例子
[C#] MessageBox.Show(bar1.YValues[3].ToString()); //顯示一個BarSeries的第4點的值(索引從0開始)。 [VB.Net] MsgBox(Bar1.YValues(3)) '顯示一個BarSeries的第4點的值(指數從0開始)。以這種方式訪問的值可用于在系列數據上設置陷阱。
[C#] for(int i = 0; i < bar1.Count; ++i) { if(bar1.YValues[i] > 500) { MessageBox.Show("Value: (" + bar1.XValues[i] + ", " + bar1.YValues[i] + ") exceeds limit"); } } [VB.Net] Dim i As Integer For i = 0 To Bar1.Count If Bar1.YValues(i) > 500 Then MsgBox("Value: (" & Bar1.XValues(i) & ", " & Bar1.YValues(i) & ") exceeds limit") End If Next同樣的值可以通過一些系列方法和一些圖表事件所使用的ValueIndex點獲得。
[C#] private void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, System.Windows.Forms.MouseEventArgs e) { if(s.Equals(bar1)) { MessageBox.Show("ValueIndex is: " + valueIndex.ToString()); MessageBox.Show("Point's YValue is " + bar1.YValues[valueIndex].ToString()); } } [VB.Net] Private Sub TChart1_ClickSeries(ByVal sender As Object, ByVal s As Steema.TeeChart.Styles.Series, ByVal valueIndex As Integer, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.ClickSeries If s Is Bar1 Then MsgBox("ValueIndex is: " & valueIndex) MsgBox("Point's YValue is " & Bar1.YValues(valueIndex)) End If End Sub使用數值的例子
這段代碼根據用戶的鼠標點擊來修改一個BarSeries Bar的值。
例子
使用TChart.ClickSeries事件來確定用戶的點擊位置。
[C#] private void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, System.Windows.Forms.MouseEventArgs e) { UpDatePoint(valueIndex,tChart1.Axes.Left.CalcPosPoint((e.Y))); } [VB.Net] Private Sub TChart1_ClickSeries(ByVal sender As Object, ByVal s As Steema.TeeChart.Styles.Series, ByVal valueIndex As Integer, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.ClickSeries UpDatePoint(valueIndex, TChart1.Axes.Left.CalcPosPoint(e.Y)) End Sub調用UpdatePoint子程序來修改Bar的值。
[C#] private void UpDatePoint(int Bar, double Y) { if(Bar < tChart1.Series[0].Count) { tChart1.Series[0].YValues[Bar] = Y; tChart1.Series[0].Repaint(); } } [VB.Net] Private Sub UpDatePoint(ByVal Bar As Integer, ByVal Y As Double) If Bar < TChart1.Series(0).Count Then TChart1.Series(0).YValues(Bar) = Y TChart1.Series(0).Repaint() End If End Sub系列事件
上一節介紹了系列事件的一些用法。本節展示了一些額外的用途。
OnClickSeries
你可以使用OnClickSeries事件來獲取關于系列的幾乎所有信息(見 "訪問系列值 "一節)。
這些例子適用于具有Datetime數據的系列,例如,這些測試值可用于以下事件的例子。
[C#] private void button1_Click(object sender, System.EventArgs e) { Random rnd = new Random(); line1.XValues.DateTime = true; line1.Pointer.Visible = true; line1.Add(DateTime.Parse("25/12/2002 10:30:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("25/12/2002 22:30:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("26/12/2002 09:20:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("26/12/2002 23:30:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("27/12/2002 11:10:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("27/12/2002 20:15:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("28/12/2002 08:15:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("28/12/2002 21:45:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("29/12/2002 12:45:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("29/12/2002 22:05:00"),rnd.Next(100),"", Color.Red); line1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top; } private void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, System.Windows.Forms.MouseEventArgs e) { //The below will show the Value of the nearest Point, not the exact Axis value at the clicked X and Y. MessageBox.Show("Date is: " + DateTime.FromOADate(line1.XValues[valueIndex]) + " Value is: " + line1.YValues[valueIndex]); } [VB.Net] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim rnd As New Random() Line1.XValues.DateTime = True Line1.Pointer.Visible = True Line1.Add(DateTime.Parse("25/12/2002 10:30:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("25/12/2002 22:30:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("26/12/2002 09:20:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("26/12/2002 23:30:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("27/12/2002 11:10:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("27/12/2002 20:15:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("28/12/2002 08:15:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("28/12/2002 21:45:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("29/12/2002 12:45:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("29/12/2002 22:05:00"), rnd.Next(100), "", Color.Red) Line1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top End Sub Private Sub TChart1_ClickSeries(ByVal sender As Object, ByVal s As Steema.TeeChart.Styles.Series, ByVal valueIndex As Integer, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.ClickSeries 'The below will show the Value of the nearest Point, not the exact Axis value at the clicked X and Y. MsgBox("Date is: " & DateTime.FromOADate(Line1.XValues(valueIndex)) _ & " Value is: " & Line1.YValues(valueIndex)) End SubOnGetSeriesPointerStyle
對于那些使用TChart指針的系列,你可以使用OnGetSeriesPointer事件訪問和修改指針。
如果指針比上一次高,就畫一個上三角,如果低,就畫一個下三角,等等。
[C#] private void line1_GetPointerStyle(Steema.TeeChart.Styles.CustomPoint series, Steema.TeeChart.Styles.GetPointerStyleEventArgs e) { if(e.ValueIndex > 0) { if(line1.YValues[e.ValueIndex] > line1.YValues[e.ValueIndex - 1]) { e.Style = Steema.TeeChart.Styles.PointerStyles.Triangle; } else if(line1.YValues[e.ValueIndex] < line1.YValues[e.ValueIndex - 1]) { e.Style = Steema.TeeChart.Styles.PointerStyles.DownTriangle; } else { e.Style = Steema.TeeChart.Styles.PointerStyles.Diamond; } } else { e.Style = Steema.TeeChart.Styles.PointerStyles.Diamond; } } [VB.Net] Private Sub Line1_GetPointerStyle(ByVal series As Steema.TeeChart.Styles.CustomPoint, ByVal e As Steema.TeeChart.Styles.GetPointerStyleEventArgs) Handles Line1.GetPointerStyle If e.ValueIndex > 0 Then If (Line1.YValues(e.ValueIndex) > Line1.YValues(e.ValueIndex - 1)) Then e.Style = Steema.TeeChart.PointerStyles.Triangle ElseIf (Line1.YValues(e.ValueIndex) < Line1.YValues(e.ValueIndex - 1)) Then e.Style = Steema.TeeChart.Styles.PointerStyles.DownTriangle Else e.Style = Steema.TeeChart.Styles.PointerStyles.Diamond End If Else e.Style = Steema.TeeChart.Styles.PointerStyles.Diamond End If End SubOnGetSeriesMark
使用OnGetSeriesMark事件,在運行時修改Mark的內容。下面的代碼根據相對于最后一個的值來改變MarkText的內容。
TeeChart支持通過DragMarks工具在重疊的情況下拖動Mark。
[C#] private void line1_GetSeriesMark(Steema.TeeChart.Styles.Series series, Steema.TeeChart.Styles.GetSeriesMarkEventArgs e) { if(e.ValueIndex > 0) { if(line1.YValues[e.ValueIndex] > line1.YValues[e.ValueIndex - 1]) { e.MarkText = e.MarkText + " (Up)"; } else if(line1.YValues[e.ValueIndex] < line1.YValues[e.ValueIndex - 1]) { e.MarkText = e.MarkText + " (Down)"; } else { e.MarkText = e.MarkText + " (No Change)"; } } } [VB.Net] Private Sub Line1_GetSeriesMark(ByVal series As Steema.TeeChart.Styles.Series, ByVal e As Steema.TeeChart.Styles.GetSeriesMarkEventArgs) Handles Line1.GetSeriesMark If (e.ValueIndex > 0) Then If (Line1.YValues(e.ValueIndex) > Line1.YValues(e.ValueIndex - 1)) Then e.MarkText = e.MarkText + " (Up)" ElseIf (Line1.YValues(e.ValueIndex) < Line1.YValues(e.ValueIndex - 1)) Then e.MarkText = e.MarkText + " (Down)" End If Else e.MarkText = e.MarkText + " (No Change)" End If End Sub最后2個事件產生的圖表外觀是
現TeeChart for .NET已加入在線訂購,現在搶購可立享優惠!
如果您對該圖表控件感興趣,歡迎加入圖表控件QQ交流群:740060302
關注慧聚IT微信公眾號???,了解產品的最新動態及最新資訊。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: