ZedGraph控件屬性及基礎(chǔ)教程詳解.doc_第1頁(yè)
ZedGraph控件屬性及基礎(chǔ)教程詳解.doc_第2頁(yè)
ZedGraph控件屬性及基礎(chǔ)教程詳解.doc_第3頁(yè)
ZedGraph控件屬性及基礎(chǔ)教程詳解.doc_第4頁(yè)
ZedGraph控件屬性及基礎(chǔ)教程詳解.doc_第5頁(yè)
已閱讀5頁(yè),還剩28頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

ZedGraph 屬性及基礎(chǔ)教程ZedGraph控件屬性設(shè)置ZedGraph是一個(gè)非常優(yōu)秀的開(kāi)源的作圖控件ZedGraph來(lái)源:/project/showfiles.php?group_id=114675ZedGraph相關(guān)例子資源:/wiki/index.php?title=Sample_Graphs1、在vs中使用ZedGraph2、 基本一些概念幾個(gè)注意點(diǎn):圖片的保存路徑設(shè)置:RenderedImagePath屬性中設(shè)置,程序?qū)υ撐募A應(yīng)該是有寫(xiě)和修改權(quán)限的圖片的輸出格式:OutputFormat屬性中設(shè)置,Png的推薦,比較清晰。Chart ChartBorder 圖表區(qū)域的邊框設(shè)置 ChartFill 圖表區(qū)域的背景填充 Legend 圖表的注釋標(biāo)簽顯示設(shè)置項(xiàng)目,一組數(shù)據(jù)對(duì)應(yīng)一種顏色的注釋 IsHStack 當(dāng)有多個(gè)顯示項(xiàng)的時(shí)候設(shè)置Y軸數(shù)據(jù)是疊加的還是分開(kāi)的 Xaxis 圖表區(qū)域的X軸相關(guān)信息設(shè)置 AxisColor 坐標(biāo)軸顏色 Cross 坐標(biāo)的原點(diǎn),可以設(shè)置坐標(biāo)的偏移程度 CrossAuto 原點(diǎn)自動(dòng)設(shè)置:True的話Cross的設(shè)置就無(wú)效了。 FontSpec X軸標(biāo)題字體相關(guān)信息 Angle X軸標(biāo)題字體顯示時(shí)候的角度,0為水平 90為垂直 Fill X軸標(biāo)題字體填充信息 ColorOpacity 透明度 IsScaled 設(shè)置X軸標(biāo)題字體顯示大小是否根據(jù)圖的比例放大縮小 RangeMax 填充時(shí)候的最大傾斜度(有過(guò)渡色,沒(méi)試過(guò)) RangeMin 填充時(shí)候的最小傾斜度(有過(guò)渡色,沒(méi)試過(guò)) StringAlignment X軸標(biāo)題字體排列(不清楚,沒(méi)試過(guò)) IsOmitMag 是否顯示指數(shù)冪(10次方,沒(méi)試過(guò),似乎與IsUseTenPower有關(guān)系) IsPreventLabelOverlap 坐標(biāo)值顯示是否允許重疊,如果False的話,控件會(huì)根據(jù)坐標(biāo)值長(zhǎng)度自動(dòng)消除部分坐標(biāo)值的顯示狀態(tài) IsShowTitle X軸標(biāo)題是否顯示 IsTicsBetweenLabels 兩個(gè)坐標(biāo)值之間是否自動(dòng)顯示分隔標(biāo)志 IsUseTenPower 是否使用10次冪指數(shù) IsVisible 是否顯示X軸 IsZeroLine 當(dāng)數(shù)據(jù)為0時(shí)候是否顯示(在餅狀圖顯示的時(shí)候有用) MajorGrid 大跨度的X軸表格虛線線顯示信息 DashOff 虛線中孔間距 DashOn 虛線單位長(zhǎng)度 MajorTic 大跨度的X軸刻度信息 IsInside 在Chart內(nèi)部是否顯示 IsOutSide 在Chart外部是否顯示 IsOpposite 在對(duì)面的軸上是否顯示 MinorGrid 小跨度的X軸表格虛線顯示信息 MinorTic 小跨度的x軸刻度信息 MinSpace 刻度和軸之間的距離(沒(méi)試過(guò)) Scale 刻度值的一些設(shè)定 IsReverse X軸的刻度值從高到低還是從低到高 MajorStep 大刻度步長(zhǎng) MajorStepAuto 是否自動(dòng)設(shè)置大刻度步長(zhǎng) MajorUnit 大刻度步長(zhǎng)單位 Max 刻度最大值 MaxAuto 根據(jù)輸入數(shù)據(jù)自動(dòng)設(shè)置刻度最大值 Min 刻度最小值 MinAuto 根據(jù)輸入數(shù)據(jù)自動(dòng)設(shè)置刻度最小值 MinGrace 不清楚,沒(méi)試過(guò) MinorStep 小刻度步長(zhǎng) MinorStepAuto 是否自動(dòng)設(shè)置小刻度步長(zhǎng) MinorUnit 小刻度單位 Type 數(shù)據(jù)顯示方式 Liner直接現(xiàn)實(shí)(自動(dòng)) Date按日期方式顯示 Log 按指數(shù)冪方式顯示 Ordinal順序顯示 Y2Axis 第二個(gè)Y軸坐標(biāo)信息顯示(具體設(shè)置看X軸) Yaxis 第一個(gè)Y軸坐標(biāo)信息顯示(具體設(shè)置看X軸)GraphPane BarBase 在生成柱狀圖的時(shí)候設(shè)置柱狀是基于X軸還是其他軸 BarType 柱狀的類(lèi)型疊加或其他。 IsFontsScaled 圖比例變化時(shí)候圖表上的文字是否跟著自動(dòng)縮放 IsIgnoreInitial 是否忽略初始值 IsIgnoreMissing 是否忽略缺省值 IsPenWidthScaled 圖比例變化時(shí)候圖表上的畫(huà)筆的粗細(xì)是否跟著自動(dòng)縮放 IsShowTitle 圖表標(biāo)題是否顯示 PaneFill Pane的一些填充信息MasterPane BaseDimension 縮放比例基數(shù)(可以試試效果) 數(shù)據(jù) 未測(cè)試過(guò)。不知道如何和數(shù)據(jù)庫(kù)綁定外觀 IsImageMap 不清楚干嗎用的行為 AxisChaneged 是否允許自動(dòng)繪圖(沒(méi)試過(guò),一般都true,動(dòng)態(tài)繪圖) CacheDuration Cache保存時(shí)間0 OutputFormat 輸出格式 RenderedImagePath 輸出路徑 RenderMode 輸出模式,不太清楚一般都是ImageTag,另一個(gè)輸出的是亂碼不是圖片對(duì)于圖表而言,一般是三種表現(xiàn)形式:柱狀圖、餅狀圖和點(diǎn)線圖?;窘坛唐?第一節(jié):InitialSampleDemo.cs介紹為了講解方便,我先附上源代碼和效果圖。代碼如下:using System;using System.Drawing;using System.Collections;using ZedGraph;namespace ZedGraph.Demo / / Summary description for SimpleDemo. / public class InitialSampleDemo : DemoBase public InitialSampleDemo() : base( Code Project Initial Sample,Initial Sample, DemoType.Tutorial ) GraphPane myPane = base.GraphPane; / Set the title and axis labels myPane.Title = My Test Graphn(For CodeProject Sample); myPane.XAxis.Title = My X Axis; myPane.YAxis.Title = My Y Axis; / Make up some data arrays based on the Sine function PointPairList list1 = new PointPairList(); PointPairList list2 = new PointPairList(); for ( int i=0; i36; i+ ) double x = (double) i + 5; double y1 = 1.5 + Math.Sin( (double) i * 0.2 ); double y2 = 3.0 * ( 1.5 + Math.Sin( (double) i * 0.2 ) ); list1.Add( x, y1 ); list2.Add( x, y2 ); / Generate a red curve with diamond / symbols, and Porsche in the legend LineItem myCurve = myPane.AddCurve( Porsche,list1, Color.Red, SymbolType.Diamond ); / Generate a blue curve with circle / symbols, and Piper in the legend LineItem myCurve2 = myPane.AddCurve( Piper,list2, Color.Blue, SymbolType.Circle ); base.ZedGraphControl.AxisChange(); 我們可以看到,InitialSampleDemo繼承自CemoBase類(lèi),而DemoBase又繼承自ZedGraphDemo這個(gè)接口。ZedGraphDemo接口定義了String Description、String Title、ZedGraph. ZedGraphControl ZedGraphControl 和 System.Collection.ICollection Types這四個(gè)屬性。DemoBase除了實(shí)現(xiàn)這四個(gè)屬性外,還添加了PaneBase Pane和MasterPane MasterPane這兩個(gè)屬性,此外DemoBase還實(shí)現(xiàn)了多載構(gòu)造函數(shù)。關(guān)于各個(gè)類(lèi)的具體含義和用法,我會(huì)在以后的篇幅中陸續(xù)介紹。這里只是給大家一個(gè)整體的大致結(jié)構(gòu)。 下面進(jìn)行對(duì)代碼的分析,由于這是第一個(gè)例子,所有我會(huì)講得比較細(xì),以后的例子就不會(huì)了。 我們可以看到程序首先public InitialSampleDemo() : base( Code Project Initial Sample ,Initial Sample, DemoType.Tutorial )初始化基類(lèi)的構(gòu)造函數(shù)?;?lèi)重載了四個(gè)構(gòu)造函數(shù)public DemoBase( string description, string title, DemoType type ) ArrayList types = new ArrayList(); types.Add( type ); Init( description, title, types ); public DemoBase( string description, string title, DemoType type, DemoType type2 ) ArrayList types = new ArrayList(); types.Add( type ); types.Add( type2 ); Init( description, title, types ); public DemoBase( string description, string title, ICollection types ) Init( description, title, types ); private void Init( string description, string title, ICollection types ) this.description = description; this.title = title; this.types = types; control = new ZedGraphControl(); 函數(shù)中的變量含義如下:Description:對(duì)此結(jié)構(gòu)的描述。Title:在樹(shù)形結(jié)構(gòu)(TreeView)中顯示的標(biāo)題。Types:要把此類(lèi)顯示在哪個(gè)樹(shù)形結(jié)構(gòu)的區(qū)域中。若有多個(gè)Types,則把此類(lèi)分入不同的樹(shù)形區(qū)域中。例如MasterPane Sample在Tutorial Sample和 Special Features兩個(gè)區(qū)域都有。見(jiàn)圖中的相應(yīng)區(qū)域標(biāo)注。myPane.Title = My Test Graphn(For CodeProject Sample); myPane.XAxis.Title = My X Axis; myPane.YAxis.Title = My Y Axis; 分別指定這個(gè)Pane的title、XAxis和YAxis的標(biāo)題。見(jiàn)上圖。PointPairList list1 = new PointPairList(); PointPairList list2 = new PointPairList(); for ( int i=0; i36; i+ ) double x = (double) i + 5; double y1 = 1.5 + Math.Sin( (double) i * 0.2 ); double y2 = 3.0 * ( 1.5 + Math.Sin( (double) i * 0.2 ) ); list1.Add( x, y1 ); list2.Add( x, y2 ); PointPairList類(lèi)是一個(gè)集合類(lèi),繼承自System.Object System.Collections.CollectionBaseZedGraph.CollectionPlus它是PointPair對(duì)象的集合,PointPair類(lèi)是一個(gè)包含(X,Y)的坐標(biāo)類(lèi)。其中的for循環(huán)在為兩個(gè)PointPairList復(fù)值。LineItem myCurve = myPane.AddCurve( Porsche, list1, Color.Red, SymbolType.Diamond );LineItem類(lèi)是ZedGraph中的線條類(lèi).myPane.AddCurve( Porsche, list1, Color.Red, SymbolType.Diamond );的意思是將剛剛賦值的list以”P(pán)orsche”這個(gè)名字以紅色和水晶形狀畫(huà)到Pane中,這個(gè)函數(shù)的返回值是一個(gè)LineItem。你可以通過(guò)myCurve這個(gè)變量來(lái)對(duì)它進(jìn)行進(jìn)一步的設(shè)定。其中SymbolType是個(gè)Enum,它枚舉了12個(gè)可供使用的形狀最后一步就是刷新了。base.ZedGraphControl.AxisChange();這樣整個(gè)程序就完成了,簡(jiǎn)單吧,其實(shí)這是個(gè)簡(jiǎn)單的應(yīng)該,以后會(huì)介紹更加復(fù)雜的用法和類(lèi)庫(kù)?;窘坛唐?第二節(jié):ModInitialSampleDemo.cs介紹為了講解方便,我先附上源代碼和效果圖。代碼如下:using System;using System.Drawing;using System.Collections;using ZedGraph;namespace ZedGraph.Demo / / Summary description for SimpleDemo. / public class ModInitialSampleDemo : DemoBase public ModInitialSampleDemo() : base( Code Project Modified Initial Sample, Modified Initial Sample, DemoType.Tutorial ) GraphPane myPane = base.GraphPane; / Set up the title and axis labels myPane.Title = My Test Graphn(For CodeProject Sample); myPane.XAxis.Title = My X Axis; myPane.YAxis.Title = My Y Axis; / Make up some data arrays based on the Sine function PointPairList list1 = new PointPairList(); PointPairList list2 = new PointPairList(); for ( int i=0; i36; i+ ) double x = (double) i + 5; double y1 = 1.5 + Math.Sin( (double) i * 0.2 ); double y2 = 3.0 * ( 1.5 + Math.Sin( (double) i * 0.2 ) ); list1.Add( x, y1 ); list2.Add( x, y2 ); / Generate a red curve with diamond / symbols, and Porsche in the legend LineItem myCurve = myPane.AddCurve( Porsche,list1, Color.Red, SymbolType.Diamond ); / Generate a blue curve with circle / symbols, and Piper in the legend LineItem myCurve2 = myPane.AddCurve( Piper,list2, Color.Blue, SymbolType.Circle ); / Change the color of the title myPane.FontSpec.FontColor = Color.Green; / Add gridlines to the plot, and make them gray myPane.XAxis.IsShowGrid = true; myPane.YAxis.IsShowGrid = true; myPane.XAxis.GridColor = Color.LightGray; myPane.YAxis.GridColor = Color.LightGray; / Move the legend location base.Pane.Legend.Position = ZedGraph.LegendPos.Bottom; / Make both curves thicker myCurve.Line.Width = 2.0F; myCurve2.Line.Width = 2.0F; / Fill the area under the curves myCurve.Line.Fill = new Fill( Color.White, Color.Red, 45F ); myCurve2.Line.Fill = new Fill( Color.White, Color.Blue, 45F ); / Increase the symbol sizes, and fill them with solid white myCurve.Symbol.Size = 8.0F; myCurve2.Symbol.Size = 8.0F; myCurve.Symbol.Fill = new Fill( Color.Red ); myCurve2.Symbol.Fill = new Fill( Color.White ); / Add a background gradient fill to the axis frame myPane.AxisFill = new Fill( Color.White, Color.FromArgb( 255, 255, 210), -45F ); / Add a caption and an arrow TextItem myText = new TextItem( InterestingnPoint, 23F, 7F ); myText.FontSpec.FontColor = Color.Red; myText.Location.AlignH = AlignH.Center; myText.Location.AlignV = AlignV.Top; myPane.GraphItemList.Add( myText ); ArrowItem myArrow = new ArrowItem( Color.Red, 12F, 7F, 5F, 20F, 8F ); myPane.GraphItemList.Add( myArrow ); base.ZedGraphControl.AxisChange(); 我們可以看到,這個(gè)例子和第一節(jié)中的例子大部分都相同,我在這只講它們不同的地方,和不好懂的地方。 和第一節(jié)的圖相比,本節(jié)的圖在Pane上添加了Grid的顯示,其功能要?dú)w功于如下代碼: myPane.XAxis.IsShowGrid = true; myPane.YAxis.IsShowGrid = true; myPane.XAxis.GridColor = Color.LightGray; myPane.YAxis.GridColor = Color.LightGray;代碼一目了然,我就不用多解釋什么了,要說(shuō)的是注意在ZedGraph中,很多都是有缺省值的,IsShowGrid的缺省值就是false,所以第一節(jié)中沒(méi)有對(duì)此項(xiàng)進(jìn)行設(shè)置就沒(méi)有顯示Grid。上節(jié)我就已經(jīng)說(shuō)過(guò)LineItem myCurve = myPane.AddCurve( Porsche,list1, Color.Red, SymbolType.Diamond );myCurve接收myPane.AddCurve的返回值后就可以對(duì)里面的線圖作近一步的描述,myCurve.Line.Width = 2.0F;、myCurve.Line.Fill = new Fill( Color.White, Color.Red, 45F ); 和myCurve.Symbol.Fill = new Fill( Color.Red );就是其中的三個(gè)應(yīng)用,一個(gè)是Line的寬度,第二個(gè)表示Line要填充下面的區(qū)域,以45度角從左到右從白到紅的填充,第三個(gè)表示線圖上的符號(hào)被填充成什么顏色的。效果見(jiàn)下圖:關(guān)于Legend的類(lèi)請(qǐng)見(jiàn)下圖:base.Pane.Legend.Position = ZedGraph.LegendPos.Bottom;就是顯示Pane中的圖形的名字,它里面也有很多屬性和方法,如果大家寫(xiě)上base.Pane.Legend.IsVisible = false ;那么就可以隱藏圖形的名字。TextItem類(lèi)的主要方法是在Pane中顯示一個(gè)textbox的文本框,見(jiàn)上圖ArrowItem類(lèi)的主要方法是在Pane上顯示一個(gè)箭頭,ArrowItem myArrow = new ArrowItem( Color.Red, 12F, 7F, 5F, 20F, 8F );構(gòu)造函數(shù)的參數(shù)含義分別為顏色,箭頭的大小,箭頭的起始(x,y),終止(x,y)?;窘坛唐?第三節(jié)、第四節(jié)DateAxisSampleDemo.cs和TextAxisSampleDemo.cs介紹 由于這兩個(gè)例子很簡(jiǎn)單也很相似,所以決定還是放到一起來(lái)寫(xiě)。按照慣例還是先給出代碼和圖示。代碼如下:DateAxisSampleDemo:using System;using System.Drawing;using System.Collections;using ZedGraph;namespace ZedGraph.Demo / / Summary description for SimpleDemo. / public class DateAxisSampleDemo : DemoBase public DateAxisSampleDemo() : base( Code Project Date Axis Sample,Date Axis Sample, DemoType.Tutorial ) GraphPane myPane = base.GraphPane; / Set the titles and axis labels myPane.Title = My Test Date Graph; myPane.XAxis.Title = Date; myPane.YAxis.Title = My Y Axis; / Make up some data points based on the Sine function PointPairList list = new PointPairList(); for ( int i=0; i36; i+ ) double x = (double) new XDate( 1995, 5, i+11 ); double y = Math.Sin( (double) i * Math.PI / 15.0 ); list.Add( x, y ); / Generate a red curve with diamond / symbols, and My Curve in the legend LineItem myCurve = myPane.AddCurve( My Curve, list, Color.Red, SymbolType.Diamond ); / Set the XAxis to date type myPane.XAxis.Type = AxisType.Date; base.ZedGraphControl.AxisChange(); TextAxisSampleDemo:using System;using System.Drawing;using System.Collections;using ZedGraph;namespace ZedGraph.Demo / / Summary description for SimpleDemo. / public class TextAxisSampleDemo : DemoBase public TextAxisSampleDemo() : base( Code Project Text Axis Sample,Text Axis Sample, DemoType.Tutorial ) GraphPane myPane = base.GraphPane; / Set the title and axis labels myPane.Title = My Test Date Graph; myPane.XAxis.Title = Label; myPane.YAxis.Title = My Y Axis; / Make up some data points string labels = USA, SpainnMadrid, Qatar, Morocco, UK, Uganda, Cambodia, Malaysia, Australia, Ecuador ; double y = new double10; for ( int i=0; i10; i+ ) yi = Math.Sin( (double) i * Math.PI / 2.0 ); / Generate a red curve with diamond / symbols, and My Curve in the legend LineItem myCurve = myPane.AddCurve( My Curve,null, y, Color.Red, SymbolType.Diamond ); /Make the curve smooth myCurve.Line.IsSmooth = true; / Set the XAxis to Text type myPane.XAxis.Type = AxisType.Text; / Set the XAxis labels myPane.XAxis.TextLabels = labels; / Set the labels at an angle so they dont overlap myPane.XAxis.ScaleFontSpec.Angle = 40; base.ZedGraphControl.AxisChange(); 看到前兩節(jié)的介紹,這里的代碼就應(yīng)該很簡(jiǎn)單了,我要說(shuō)的只有兩個(gè)類(lèi)XDate和TextLabel這個(gè)屬性。首先XDate就相當(dāng)于msdn中的DateTime這個(gè)類(lèi),是個(gè)時(shí)間日期類(lèi),也是具有多個(gè)構(gòu)造函數(shù),XDate( 1995, 5, i+11 )是按年月日來(lái)初始化的。第二個(gè)就是TextLabel屬性,它主要是把Label的內(nèi)容顯示在Pane上。如TextAxisSampleDemo的X軸?;窘坛唐?第五節(jié)BarChartSampleDemo.cs介紹 從這節(jié)開(kāi)始,我們將進(jìn)入柱形圖的研究(如下圖),首先從最簡(jiǎn)單的BarChartSampleDemo開(kāi)始,我們一步一步進(jìn)入ZedGraph的柱形世界。代碼如下:using System;using System.Drawing;using System.Collections;using ZedGraph;namespace ZedGraph.Demo / / Summary description for SimpleDemo. / public class BarChartSampleDemo : DemoBase public BarChartSampleDemo() : base( Code Project Bar Chart Sample,Bar Chart Sample, DemoType.Tutorial ) GraphPane myPane = base.GraphPane; / Set the titles and axis

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論