翻譯|使用教程|編輯:董玉霞|2022-07-14 11:07:22.097|閱讀 250 次
概述:本文主要介紹TeeChart for .NET使用教程中關于使用系列的相關介紹。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
本文主要介紹TeeChart for .NET使用教程中關于使用系列的相關介紹。
TChart Series 類是所有 Series 類型的共同祖先。當使用 TeeChart 在線幫助獲取有關任何系列類型的幫助時,請點擊位于繼承類型列表中的系列類的鏈接,然后單擊系列成員,其中將包含所有繼承屬性和方法的列表。
作為 TeeChart 類型庫結構的一點背景知識,這里是對 Series 類和接口的解釋。下圖顯示了 TeeChart Series 類之間的關系。所有類都派生自通用“Series”類,因此共享“Series”屬性和方法。幾個抽象類派生自 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 屬性和方法都可用于新系列。
在同一圖表中混合不同系列類的示例是在設計時使用 TeeChart 編輯器將區域(系列(0))、條形(系列(1))和線(系列(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
為圖表選擇系列類型在很大程度上取決于您自己對圖表的要求。然而,在某些情況下,由于要繪制的變量數量,圖表的選擇可能取決于哪些系列類型支持輸入變量的數量。下表顯示了每個系列類型允許的變量數。
標簽可用于擴展 2 變量系列類型的值。請參閱下面的示例,該示例在同一圖表中使用 3 個 Bar Series 類型的實例。
例:
使用酒吧系列類型
產品代碼 | 月份 | 生產數量 |
10 | 一月 | 300 |
10 | 二月 | 325 |
10 | 三月 | 287 |
12 | 一月 | 175 |
12 | 二月 | 223 |
12 | 三月 | 241 |
14 | 一月 | 461 |
14 | 二月 | 470 |
14 | 三月 | 450 |
以最簡單的形式,數據生成以下圖表,按月份對信息進行分組:
[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"
我們在上表(庫存)中添加了新值。
產品代碼 | 月份 | 生產數量 | 庫存水平 |
10 | 一月 | 300 | 600 |
10 | 二月 | 325 | 715 |
10 | 三月 | 287 | 676 |
12 | 一月 | 175 | 245 |
12 | 二月 | 223 | 270 |
12 | 三月 | 241 | 315 |
14 | 一月 | 461 | 800 |
14 | 二月 | 470 | 755 |
14 | 三月 | 455 | 835 |
表中的庫存值通常高于月產量,因此顯示它們會給出以下圖表(這次是 2D)。該圖表使用線系列來區分股票。
代碼:
將以下代碼添加到前面第一個示例的代碼中:
[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
大多數 Series 類型(ADO.NET 數據源教程 8 和函數教程 7 除外)使用 Add 方法的 24 個泛型重載來添加數據。
請注意,除了 ShapeSeries 之外,所有特定于 Series 的 Add 方法都會自動添加為通用 Add 方法的進一步重載,因此可以從那里訪問(例如,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
可以將透明顏色添加到 Point 以保留 ValueList 中的值的空間,而不顯示在 Chart 上。
[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 個點開始刪除多個點 n。
[C#] 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 清除系列中的所有點。
Series.Add 具有三個重載,可讓您將 Null 點添加到系列:
添加一個新的空(透明)點。
公共 Int32 添加()
添加具有指定文本的新空點。
公共 Int32 添加(System.String)
在具有指定文本的指定 x 值處添加新的空點。
公共 Int32 添加(System.Double,System.String)
上述第二個重載將為系列添加一個空點,允許您為該點定義一個標簽,但在該點在系列中留下一個中斷。在線系列的情況下,中斷前的最后一個點不會連接到中斷后的第一個點。
[C#] line1.Add("Null Point"); [VB.Net] Line1.Add("Null Point")
請在 TeeChart 幫助文件中查找其他兩個重載以獲取它們的使用示例。
本次關于.NET圖表控件TeeChart for .NET的教程就介紹到這里了,下一篇將介紹如何自定義圖例的相關內容。
TeeChart for .NET更新至最新版本v2022.6.27,修復了 打印預覽對話框為空白的問題。
如果您想了解TeeChart for .NET價格,歡迎咨詢
TeeChart for .NET 是優秀的工業4.0 WinForm圖表控件,官方獨家授權漢化,集功能全面、性能穩定、價格實惠等優勢于一體。
歡迎加入TeeChart for .NET技術交流QQ群:740060302
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn