原創|使用教程|編輯:王香|2018-08-03 10:22:44.000|閱讀 1500 次
概述:本文詳細介紹在Teechart中使用系列的實際應用
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
上一篇:
【下載TeeChart.Net最新版本】
TChart Series類是所有Series類型的父屬性,使用TeeChart在線幫助獲取任何Series Type的幫助時,請點擊繼承類型列表中Series類的鏈接,然后單擊Series成員,其中將包含所有繼承屬性和方法的列表。
1.1 系列類結構
作為TeeChart類型庫結構的一小部分背景,下面是對系列類和接口的解釋。下圖顯示了TeeChart系列類之間的關系。所有類都派生自通用的“Series”類,因此共享“Series”屬性和方法。幾個抽象類派生自Series(Custom3DSeries,CustomBarSeries和CircledSeries),這些類以灰色突出顯示,并且它們的接口不能直接用于編程,它們的特性由其后代Series類型繼承。所有派生系列(橙色)均可在TeeChart圖庫中訪問,以包含在用戶的圖表中。以這種方式派生的TeeChart系列允許通過公共索引結構對繼承的屬性和方法進行可編程訪問(請參閱本節后面的示例代碼)。
在設計時使用TChart編輯器更容易添加Series,也可以在運行時創建新的和不同的系列類型并將其添加到同一TChart。
[C#.Net]
//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屬性和方法。
在同一圖表中混合不同系列類的一個示例是在設計時使用TeeChart編輯器將區域(Series(0)), Bar (Series(1)) and Line (Series(2))系列添加到圖表中。所有訪問一個公共索引結構,圖表的系列列表。使用該系列可能如下所示:
[C#.Net]
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
1.2 選擇
系列類型為圖表選擇系列類型很大程度上取決于用戶自己對圖表的要求。但是,有時候,由于要繪制的變量數量,Chart的選擇可能取決于哪種Series類型支持輸入變量的數量。下表顯示了每種Series類型允許的變量數。
標簽可用于擴展2變量Series Type的值。請參閱下面的示例,該示例在同一圖表中使用3個Bar Series類型的實例。
示例
使用條形系列類型
產品代碼月產量數量
10 Jan 300
10 Feb 325
10 Mar 287
12 Jan 175
12 Feb 223
12 Mar 241
14 Jan 461
14 Feb 470
14 Mar 455
以最簡單的形式,數據生成以下圖表,按月對信息進行分組:
代碼:
[C#.Net]
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"
或(grouping by product):
代碼:
[C#.Net]
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"
上表(Stock)中添加了新值。
產品代碼月份數量產生庫存水平
10 Jan 300 600
10 Feb 325 715
10 Mar 287 676
12 Jan 175 245
12 Feb 223 270
12 Mar 241 315
14 Jan 461 800
14 Feb 470 755
14 Mar 455 835
表中的庫存值通常高于月產量,因此顯示它們會給出下面的圖表(這次是2D)。圖表使用線系列來區分股票。
代碼:
將以下內容添加到前面第一個示例的代碼中:
[C#.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;
[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
1.3 將數據添加到系列
大多數系列類型(ADO.NET數據源教程8和函數教程7除外)使用Add方法的24個泛型重載來添加數據。有一些例外,請參見下表:
除了ShapeSeries之外,所有系列特定的Add方法都會自動添加為通用Add方法的進一步重載,因此可以從那里訪問(例如candleSeries1.Add(new)日期時間(2002,11,27),100400200300))。添加點示例時,可以為點添加顏色
顏色
[C#.Net]
bar1.Add(50,"Tomatoes",Color.Tomato);
[VB.Net]
Bar1.Add(50, "Tomatoes", Color.Tomato)
或者,用戶可以允許TeeChart分配顏色。如果Series.ColorEach = True,TeeChart將為每個新系列選擇最多19種唯一且尚未使用的顏色之一,或者為每個新系列點選擇一種顏色。
例:
[C#.Net]
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
可以向Point添加透明顏色,以便為ValueList中的值保留空間,而不會在Chart上顯示。
例:
[C#.Net]
bar1.Add(45, "My Transparent Bar", Color.Transparent);
[VB.Net]
Bar1.Add(45, "My Transparent Bar", Color.Transparent)
1.4 從系列中刪除數據點
使用系列中刪除數據點。刪除系列中的點。Series.Delete有兩個重載:
public Void Delete(System.Int32)
刪除系列中的第n個點。
public Void Delete(System.Int32,System.Int32)
從系列的第n個點開始刪除多個點。
例:
[C#.Net]
bar1.Delete(7,2); (deletes two points starting from the 8th Series point (index starts at zero))
[VB.Net]
Bar1.Delete(7, 2) (deletes two points starting from the 8th Series point (index starts at zero))
Series.Clear清除系列中的所有點。
1.5 將Null點添加到Series
Series.Add有三個重載,允許用戶向系列添加Null點:添加一個新的null(透明)點。
public Int32 Add()
使用指定的文本添加新的null點。
public Int32 Add(System.String)
在指定的x值處添加一個帶有指定文本的新null值
public Int32 Add(System.Double,System.String)
上面的第二個重載將為系列添加一個Null點,允許你為該點定義一個標簽,但在該點為系列留下一個中斷。在Line Series的情況下,中斷前的最后一個點不會連接到中斷后的第一個點。
例
[C#.Net]
line1.Add(“Null Point”);
[VB.Net]
Line1.Add("Null Point")
TeeChart Pro提供了一個空的Chart Canvas作為數據系列的背景,這意味著沒有預定義圖表類型,用戶可以將所需的圖表類型定義為要顯示的系列類型的混合。由于某些系列類型的特殊性質,在Chart上將Series類型與另一個類型混合是不切實際的。當用戶到達添加新系列時,TeeChart會通過在圖表庫中顯示不合適的系列類型來幫助用戶。用戶可以在一個圖表中放置的系列數量沒有實際限制。
2.1 添加新系列
使用TeeChart編輯器(參見)或按代碼添加系列。
例:
[C#.Net]
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屬性修改名稱。
2.2 選擇
添加到圖表系列的軸系列會自動將左軸和下軸作為參考軸,用戶可以通過選擇相關系列的“Series General(系列常規)”頁面來更改圖表編輯器中的參考軸。有4個軸可供選擇,Top,Left,Bottom和Right。通過代碼,更改軸將如下所示:
[C#.Net]
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將決定適合與Axis匹配的系列的最佳比例,但用戶可以自己更改Axis音階(參見)。可以添加額外的軸; 他們將從前4個軸復制與其對應關聯的比例。
2.3 連接系列
用戶可以使用Series作為另一個Series的數據源,通過設置第二系列的數據源,可以使用圖表編輯器完成此操作。轉到“Series(系列)”選項卡“Datasource(數據源)”頁面,選擇“Function”作為數據源類型,將出現兩個列表框,可用系列和選定系列,選擇要用作當前系列的數據源的系列,然后在上面的Combobox中,標題為Functions:,選擇Average作為功能類型,然后單擊Apply按鈕。請注意,以這種方式,任何Series都可以定義為任何其他Series的函數,Function Type可以是Function組合框中可用的任何列表。要通過代碼執行相同操作,請參閱下文:
[C#.Net]
Steema.TeeChart.Functions.Average 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()
2.4 更改系列訂單
使用圖表編輯器更改系列訂單非常簡單,轉到編輯器的金喜正規買球,突出顯示要移動的系列。使用右側的箭頭按鈕以系列順序向上或向下移動系列。系列訂單將決定圖表中系列相對于其他系列的相對顯示位置。將系列設置為“Active=False”將從圖表中隱藏系列,但保持其數據內容不變。要通過代碼更改系列順序,請使用Series.Exchange。
[C#.Net]
tChart1.Series.Exchange(0, 1); //Change Series(0) with Series(1) in the index order
[VB.Net]
TChart1.Series.Exchange(0, 1) 'Change Series(0) with Series(1) in the index order
*注意。交換Series后,系列的索引將被更改。因此,如果代碼重新運行,上面的代碼行將永久地交換2系列'0'和'1',因為0變為1,1變為0。
TeeChart系列將其值存儲在可通過ValueList類訪問和修改的Valuelist中。
3.1 訪問系列值
用戶可以訪問列表中的任何值:
示例:
[C#.Net]
MessageBox.Show(bar1.YValues[3].ToString()); //Displays value of 4th point (index starts at 0) of a BarSeries
[VB.Net]
MsgBox(Bar1.YValues(3)) 'Displays value of 4th point (index starts at 0) of a BarSeries
以這種方式訪問??的值可用于設置Series數據:
[C#.Net]
{ 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
可以通過一些Series方法和幾個Chart事件使用的PointIndex值獲得相同的值。
例
[C#.Net]
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
3.2 使用值的示例
此代碼根據用戶的鼠標單擊修改BarSeries Bar的值。
示例
使用TChart.ClickSeries事件確定用戶單擊的位置。
[C#.Net]
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 Sub例程來修改Bar的值:
[C#.Net]
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
上一節介紹了Series事件的一些用法,本節介紹了一些其他用途。
4.1 OnClickSeries
用戶可以使用OnClickSeries事件來獲取有關Series的幾乎所有信息。
這些示例適用于具有日期時間數據的系列,例如,這些測試值可用于以下事件示例:
[C#.Net]
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 Sub
4.2 OnGetSeriesPointerStyle
對于那些使用 TChart指針的系列,用戶可以使用OnGetSeriesPointer事件訪問和修改指針:
如果Point高于最后一個,則繪制一個Uptriangle,如果更低,則繪制一個UpTriangle等。
[C#.Net]
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 Sub
4.3 OnGetSeriesMark
使用OnGetSeriesMark事件在運行時修改標記內容,以下代碼根據相對于最后一個的值改變MarkText;
TeeChart支持通過DragMarks工具在重疊的情況下拖動標記:
[C#.Net]
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個事件產生的圖表效果是:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn