翻譯|使用教程|編輯:凌霄漢|2022-03-22 16:55:55.083|閱讀 292 次
概述:本次TeeChart Pro .NET使用教程將為大家帶來如何使用系列類型。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TeeChart Pro 將自動為您定義所有 Axis 標簽,并提供足夠的靈活性來定制您可能有的任何特定要求。 TeeChart Pro 提供真正的多軸。 這些在設計或運行時可用,并為 Axis 定義提供了無數的可能性和靈活性。
TChart Series 類是所有 Series 類型的共同祖先。當使用 TeeChart 在線幫助獲取有關任何系列類型的幫助時,請點擊位于繼承類型列表中的系列類的鏈接,然后單擊系列成員,其中將包含所有繼承屬性和方法的列表。
作為 TeeChart 類型庫結構的一點背景知識,這里是對 Series 類和接口的解釋。下圖顯示了 TeeChart Series 類之間的關系。所有類都派生自通用“Series”類,因此共享“Series”屬性和方法。幾個抽象類派生自 Series(Custom3DSeries、CustomBarSeries 和 CircledSeries),它們以灰色突出顯示,并且它們的接口不能直接用于編程,它們的特性由它們的后代 Series 類型繼承。所有派生系列(橙色)都可以在 TeeChart 庫中訪問,以包含在您的圖表中。以這種方式派生的 TeeChart 系列允許通過公共索引結構對繼承的屬性和方法進行可編程訪問。
在設計時使用圖表編輯器添加系列更容易,但您也可以在運行時創建新的和不同的系列類型并將其添加到同一 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 類型的實例。
Product code | Month | Quantity produced |
---|---|---|
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#] 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"
我們在上表(庫存)中添加了新值。
Product code | Month | Quantity produced | Stock level |
---|---|---|---|
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#] 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 個泛型重載來添加數據。
添加點時可以手動為點添加顏色
[C#] bar1.Add(50,"Tomatoes",Color.Tomato); [VB.Net] Bar1.Add(50, "Tomatoes", Color.Tomato)
Alternatively, you can allow TeeChart to allocate a colour. TeeChart will choose one of up to 19 unique and as yet unused colours for each new Series, or for each new Series point if 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 for .NET正版價格,歡迎咨詢慧都在線客服
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn