翻譯|使用教程|編輯:董玉霞|2022-07-14 11:07:22.097|閱讀 250 次
概述:本文主要介紹TeeChart for .NET使用教程中關(guān)于使用系列的相關(guān)介紹。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
本文主要介紹TeeChart for .NET使用教程中關(guān)于使用系列的相關(guān)介紹。
TChart Series 類是所有 Series 類型的共同祖先。當(dāng)使用 TeeChart 在線幫助獲取有關(guān)任何系列類型的幫助時(shí),請(qǐng)點(diǎn)擊位于繼承類型列表中的系列類的鏈接,然后單擊系列成員,其中將包含所有繼承屬性和方法的列表。
作為 TeeChart 類型庫(kù)結(jié)構(gòu)的一點(diǎn)背景知識(shí),這里是對(duì) Series 類和接口的解釋。下圖顯示了 TeeChart Series 類之間的關(guān)系。所有類都派生自通用“Series”類,因此共享“Series”屬性和方法。幾個(gè)抽象類派生自 Series(Custom3DSeries、CustomBarSeries 和 CircledSeries),這些類以灰色突出顯示,并且它們的接口不能直接用于編程,它們的特性由它們的后代 Series 類型繼承。所有派生系列(橙色)都可以在 TeeChart 庫(kù)中訪問(wèn),以包含在您的圖表中。以這種方式派生的 TeeChart 系列允許通過(guò)公共索引結(jié)構(gòu)對(duì)繼承的屬性和方法進(jìn)行可編程訪問(wèn)(參見(jiàn)本節(jié)后面的示例代碼)。
在設(shè)計(jì)時(shí)使用 TChart 編輯器添加系列更容易,但您也可以在運(yùn)行時(shí)創(chuàng)建新的和不同的系列類型并將其添加到同一 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
與在設(shè)計(jì)時(shí)創(chuàng)建的任何系列一樣,所有 AreaSeries 屬性和方法都可用于新系列。
在同一圖表中混合不同系列類的示例是在設(shè)計(jì)時(shí)使用 TeeChart 編輯器將區(qū)域(系列(0))、條形(系列(1))和線(系列(2))系列添加到圖表中.所有訪問(wèn)一個(gè)共同的索引結(jié)構(gòu),圖表的系列列表。使用系列可能如下所示:
[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
為圖表選擇系列類型在很大程度上取決于您自己對(duì)圖表的要求。然而,在某些情況下,由于要繪制的變量數(shù)量,圖表的選擇可能取決于哪些系列類型支持輸入變量的數(shù)量。下表顯示了每個(gè)系列類型允許的變量數(shù)。
標(biāo)簽可用于擴(kuò)展 2 變量系列類型的值。請(qǐng)參閱下面的示例,該示例在同一圖表中使用 3 個(gè) Bar Series 類型的實(shí)例。
例:
使用酒吧系列類型
產(chǎn)品代碼 | 月份 | 生產(chǎn)數(shù)量 |
10 | 一月 | 300 |
10 | 二月 | 325 |
10 | 三月 | 287 |
12 | 一月 | 175 |
12 | 二月 | 223 |
12 | 三月 | 241 |
14 | 一月 | 461 |
14 | 二月 | 470 |
14 | 三月 | 450 |
以最簡(jiǎn)單的形式,數(shù)據(jù)生成以下圖表,按月份對(duì)信息進(jìn)行分組:
[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"
或(按產(chǎn)品分組):
[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è)谏媳恚◣?kù)存)中添加了新值。
產(chǎn)品代碼 | 月份 | 生產(chǎn)數(shù)量 | 庫(kù)存水平 |
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 |
表中的庫(kù)存值通常高于月產(chǎn)量,因此顯示它們會(huì)給出以下圖表(這次是 2D)。該圖表使用線系列來(lái)區(qū)分股票。
代碼:
將以下代碼添加到前面第一個(gè)示例的代碼中:
[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
大多數(shù) Series 類型(ADO.NET 數(shù)據(jù)源教程 8 和函數(shù)教程 7 除外)使用 Add 方法的 24 個(gè)泛型重載來(lái)添加數(shù)據(jù)。
請(qǐng)注意,除了 ShapeSeries 之外,所有特定于 Series 的 Add 方法都會(huì)自動(dòng)添加為通用 Add 方法的進(jìn)一步重載,因此可以從那里訪問(wèn)(例如,candleSeries1.Add(new DateTime(2002,11,27),100,400,200,300 );)。
添加點(diǎn)時(shí)可以手動(dòng)為點(diǎn)添加顏色。
[C#] bar1.Add(50,"Tomatoes",Color.Tomato); [VB.Net] Bar1.Add(50, "Tomatoes", Color.Tomato)
或者,您可以允許 TeeChart 分配顏色。 TeeChart 將為每個(gè)新系列選擇多達(dá) 19 種唯一且尚未使用的顏色之一,或者如果 Series.ColorEach = True,則為每個(gè)新系列點(diǎn)選擇一種。
[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 從系列中刪除一個(gè)點(diǎn)。 Series.Delete 有兩個(gè)重載:
public Void Delete(System.Int32)
刪除系列中的第 n 個(gè)點(diǎn)。
public Void Delete(System.Int32, System.Int32)
從系列中的第 n 個(gè)點(diǎn)開(kāi)始刪除多個(gè)點(diǎ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 清除系列中的所有點(diǎn)。
Series.Add 具有三個(gè)重載,可讓您將 Null 點(diǎn)添加到系列:
添加一個(gè)新的空(透明)點(diǎn)。
公共 Int32 添加()
添加具有指定文本的新空點(diǎn)。
公共 Int32 添加(System.String)
在具有指定文本的指定 x 值處添加新的空點(diǎn)。
公共 Int32 添加(System.Double,System.String)
上述第二個(gè)重載將為系列添加一個(gè)空點(diǎn),允許您為該點(diǎn)定義一個(gè)標(biāo)簽,但在該點(diǎn)在系列中留下一個(gè)中斷。在線系列的情況下,中斷前的最后一個(gè)點(diǎn)不會(huì)連接到中斷后的第一個(gè)點(diǎn)。
[C#] line1.Add("Null Point"); [VB.Net] Line1.Add("Null Point")
請(qǐng)?jiān)?TeeChart 幫助文件中查找其他兩個(gè)重載以獲取它們的使用示例。
本次關(guān)于.NET圖表控件TeeChart for .NET的教程就介紹到這里了,下一篇將介紹如何自定義圖例的相關(guān)內(nèi)容。
TeeChart for .NET更新至最新版本v2022.6.27,修復(fù)了 打印預(yù)覽對(duì)話框?yàn)榭瞻椎膯?wèn)題。
如果您想了解TeeChart for .NET價(jià)格,歡迎咨詢
TeeChart for .NET 是優(yōu)秀的工業(yè)4.0 WinForm圖表控件,官方獨(dú)家授權(quán)漢化,集功能全面、性能穩(wěn)定、價(jià)格實(shí)惠等優(yōu)勢(shì)于一體。
歡迎加入TeeChart for .NET技術(shù)交流QQ群:740060302
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn