资源描述:
《zedgraph控件生成饼图、拆线图和柱状图例程》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、这几天做了个自己觉得还蛮NB的功能,在GRID中选中一块数据,然后右键菜单即可生成三种图形,还可以互相切换,对了,饼图还添加了鼠标点击分离的处理,大致如图:用的控件就是ZedGraph,我把它继承封装了一下,方便调用:1ImportsZedGraph23PublicClassFinexGraph4'用于切换图型的5PrivatedtSourceAsDataTable6http://mz.qqtop1.com7PrivateFunctionFinexGraph_MouseDownEvent(ByValsenderAsZedGraph.ZedGraphControl,ByValeAsSystem.
2、Windows.Forms.MouseEventArgs)AsSystem.BooleanHandlesMyBase.MouseDownEvent89Ife.Button=Windows.Forms.MouseButtons.LeftThen10DimpaneAsGraphPane=sender.GraphPane11DimptAsNewPointF(e.X,e.Y)12DimcurveAsCurveItem=Nothing13Dimi%14Ifpane.FindNearestPoint(pt,curve,i)Then15Ifcurve.IsPieThen16DimpiAsPieItem=CT
3、ype(curve,PieItem)17Ifpi.Displacement>0Then18pi.Displacement=019Else20pi.Displacement=0.321EndIf22sender.Refresh()23EndIf24EndIf25EndIf26ReturnTrue2728EndFunction2930PublicSubSetTitle(ByValtitleAsString)31''Setthepanetitle32GraphPane.Title.Text=title33EndSub34http://h.78name.com35PublicSubSetPieData
4、B(ByValdtAsDataTable,ByValtitleAsString)3637'为多列一行的数据,按列分块,不支持切换,不推荐使用3839DimdsAsNewDataSet40Dimi,jAsInteger41Dimcc,rcAsInteger4243rc=dt.Rows.Count44cc=dt.Columns.Count45Ifrc=0Orcc=0ThenReturn4647GraphPane.CurveList.Clear()48GraphPane.GraphObjList.Clear()49GraphPane.Legend.IsVisible=True50GraphPane.
5、Legend.Position=LegendPos.Right51GraphPane.Legend.FontSpec.Size=752IfString.IsNullOrEmpty(title)=FalseThen53GraphPane.Title.Text=title54EndIf5556Dimlabels(cc-1)AsString57Dimvalues(cc-1)AsDouble5859Fori=0Tocc-160labels(i)=dt.Columns(i).ColumnName61values(i)=dt.Rows(0).Item(i)62Next63'Dimcolors()AsCol
6、or={Color.Red,Color.Blue,Color.Green,Color.Yellow,Color.Purple,Color.Brown,Color.Coral,Color.ForestGreen}64Dimslices()AsPieItem=GraphPane.AddPieSlices(values,labels)65GraphPane.Fill=NewFill(Color.Cornsilk)66GraphPane.Chart.Fill=NewFill(Color.Cornsilk)67'GraphPane.Fill=NewFill(Color.White,Color.Golde
7、nrod,45.0F)6869Fori=0Tocc-170slices(i).LabelType=PieLabelType.Name_Value_Percent71Next7273GraphPane.AxisChange()74Refresh()75dtSource=Nothing76FlowLayoutPanel1.Controls.Clear()7778EndSub7980PublicSubS