首页 C#.NET WinForm 绘制饼图,直方图,曲线图 详细代码

C#.NET WinForm 绘制饼图,直方图,曲线图 详细代码

举报
开通vip

C#.NET WinForm 绘制饼图,直方图,曲线图 详细代码.NETWinC#Form绘制饼图,直方图,曲线图详细代码自定义图形类(饼图,直方图,曲线图)usingSystem;usingSystem.Data;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;usingSystem.IO;usingSystem.Text;usingSystem.Data.SqlClient;usingSystem.Threading;usingSystem.Net;usingSystem.Web.Services....

C#.NET WinForm 绘制饼图,直方图,曲线图 详细代码
.NETWinC#Form绘制饼图,直方图,曲线图详细代码自定义图形类(饼图,直方图,曲线图)usingSystem;usingSystem.Data;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;usingSystem.IO;usingSystem.Text;usingSystem.Data.SqlClient;usingSystem.Threading;usingSystem.Net;usingSystem.Web.Services.Description;usingSystem.CodeDom;usingMicrosoft.CSharp;usingSystem.CodeDom.Compiler;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Security.Cryptography;usingSystem.Drawing.Imaging;usingSystem.Collections;publicclassFunc{privatestaticAChartchart=newAChart();privatestaticObject[]ChartColor={Color.Red,Color.Blue,Color.Orange,Color.Green,Color.Cyan,Color.Purple,Color.Coral,Color.Chocolate,Color.Gray,Color.Gold,Color.Lavender,Color.Linen,Color.Magenta,Color.Moccasin,Color.Navy,Color.Olive,Color.Peru,Color.Plum,Color.Purple,Color.Salmon,Color.Sienna,Color.Silver,Color.Tan,Color.Tomato,Color.Violet,Color.Turquoise,Color.Transparent};//////填充饼图、直方图、曲线图到容器里//////标题///容器(Panel,Form,TabPage)///对Table[0]进行操作,饼图取最前两列,第一列为名字,第二列为值。单数据直方图取最前两列,第一列为横轴每列名称,第二列为值。多数据直方图第一列为横轴父项名称,然后依次取前一列为横轴每列名称,后一列为值。曲线图取第一列为横轴每列名称,往后每列都代 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 一条曲线,列名为曲线名称。///图表类型///刻度最小值,此参数对饼图无效///刻度最大值,此参数对饼图无效///刻度值,此参数对饼图无效///值的单位,此参数对饼图无效publicstaticvoidDrawingChart(stringchartTitle,Controlcontrol,DataSetdataSet,ChartTypechartType,intminNumber,intmaxNumber,intscale,stringunit){DrawingChartInclude(chartTitle,control,dataSet,chartType,minNumber,maxNumber,scale,unit);}//////填充饼图到容器里//////标题///容器(Panel,Form,TabPage)///对Table[0]进行操作,取最前两列,第一列为名字,第二列为值publicstaticvoidDrawingChart(stringchartTitle,Controlcontrol,DataSetdataSet){DrawingChartInclude(chartTitle,control,dataSet,ChartType.Piegraph,0,0,0,"");}privatestaticvoidDrawingChartInclude(stringchartTitle,Controlcontrol,DataSetdataSet,ChartTypechartType,intminNumber,intmaxNumber,intscale,stringunit){if(control.Height<230||control.Width<230){");Func.Msg("容器宽度或长度设置过小!(宽度和长度必须>=230)return;}if(control.GetType().Name.Equals("Form")||control.GetType().Name.Equals("TabPage")||control.GetType().Name.Equals("GroupBox")||control.GetType().Name.Equals("Panel")){for(inti=0;i=((Control)chart[i].crtObj).Height){x=(((Control)chart[i].crtObj).Width-((Control)chart[i].crtObj).Height)/2+50;y=50;}else{x=50;y=(((Control)chart[i].crtObj).Height-((Control)chart[i].crtObj).Width)/2+50;}Penline=newPen(Color.Black,2);SolidBrushlinesb=newSolidBrush(Color.DarkGreen);Rectanglerect=newRectangle(x,y,diameter,diameter);Pentitle=newPen(Color.Blue,2);SolidBrushB=newSolidBrush(Color.Blue);StringFormatLl=newStringFormat();Ll.Alignment=System.Drawing.StringAlignment.Near;intheight=((Control)chart[i].crtObj).Height-20;RectangleFRectTitle=newRectangleF(5,5,diameter,diameter);B,RectTitle,Ll);e.Graphics.DrawString(chart[i].crtTitle,newFont("Arial",14),#region饼图if(chart[i].crtType==ChartType.Piegraph){j++)floattotal=0;floatfontWidth=0;for(intj=0;j=30){width+=(int)fontWidth+(int)e.Graphics.MeasureString(chart[i].crtUnit,newFont("Arial",10)).Width+10;}else{width+=30;}diameter);}e.Graphics.DrawLine(line,x,y+diameter,width,y+}#endregion#region曲线图elseif(chart[i].crtType==ChartType.Polygram){intwidth=x;intscaleBS=diameter/((chart[i].crtMaxNumber-chart[i].crtMinNumber)/chart[i].crtScale);intscaleWidthBS=diameter/chart[i].crtDataSet.Tables[0].Rows.Count;height=y+diameter-((chart[i].crtMaxNumber-chart[i].crtMinNumber)/chart[i].crtScale)*scaleBS;floatfontWidth=e.Graphics.MeasureString(chart[i].crtMaxNumber.ToString(),newFont("Arial",10)).Width;for(intj=0;j<=chart[i].crtDataSet.Tables[0].Rows.Count;j++){diameter);e.Graphics.DrawLine(line,width,height,width,y+width+=scaleWidthBS;}height=y+diameter-12;for(intj=chart[i].crtMinNumber;j<=chart[i].crtMaxNumber;j+=chart[i].crtScale){e.Graphics.DrawLine(line,x,height+12,x+scaleWidthBS*chart[i].crtDataSet.Tables[0].Rows.Count,height+12);RectangleFRectScaleHeightLine=newRectangleF(x-fontWidth-1,height,diameter,diameter);e.Graphics.DrawString(j.ToString(),newFont("Arial",10),linesb,RectScaleHeightLine,Ll);height-=scaleBS;j++)}width=x;height=y+diameter;doublenowheight=0;for(intj=0;j0){aa=y+diameter-Convert.ToDouble(chart[i].crtDataSet.Tables[0].Rows[j-1][k].ToString())/chart[i].crtScale*scaleBS;}nowheight=y+diameter-Convert.ToDouble(chart[i].crtDataSet.Tables[0].Rows[j][k].ToString())/chart[i].crtScale*scaleBS;e.Graphics.DrawLine(polygramLine,width,(int)aa,width+scaleWidthBS,(int)nowheight);RectangleFRectScale=newRectangleF(width+scaleWidthBS,(int)nowheight-12,diameter,diameter);e.Graphics.DrawString(chart[i].crtDataSet.Tables[0].Rows[j][k].ToString()+chart[i].crtUnit,newFont("Arial",10),valueSB,RectScale);}width+=scaleWidthBS;}fontWidth=0;for(intj=1;jCount-1||index<0){}else{}MessageBox.Show("Indexnotvalid!");List.RemoveAt(index);}publicAChartItem{get{}}returnthis;[System.Runtime.CompilerServices.IndexerName("item")]publicpChartthis[intindex]{get{}}}return(pChart)List[index];//////图表类型///publicenumChartType{//////直方图///Histogram,//////饼图///Piegraph,//////曲线图///Polygram,//////None///None}测试用例:privatevoidbutton1_Click(objectsender,EventArgse){DataSetds=newDataSet();ds=Func.DBbind("select'甲'asname,50asvalueunionallselect'乙',60unionallselect'丙',70unionallselect'丁',80");Func.DrawingChart("饼图测试",this.panel1,ds);}privatevoidbutton2_Click(objectsender,EventArgse){DataSetds=newDataSet();ds=Func.DBbind("select'甲'asname,50asvalueunionallselect'乙',60unionallselect'丙',70unionallselect'丁',80");Func.DrawingChart("直方图一测试",this.panel1,ds,ChartType.Histogram,0,100,10,"万");}privatevoidbutton3_Click(objectsender,EventArgse){DataSetds=newDataSet();ds=Func.DBbind("select'一月'as月份,'甲'asname,50asvalue,'乙'asname2,60asvalue2unionallselect'二月'as月份,'甲',70,'乙',80");Func.DrawingChart("直方图一测试",this.panel1,ds,ChartType.Histogram,0,100,10,"万");}privatevoidbutton4_Click(objectsender,EventArgse){DataSetds=newDataSet();ds=Func.DBbind("select'一月'as月份,50as甲,60as乙unionallselect'二月',60,40unionallselect'三月',70,50unionallselect'四月',30,60unionallselect'五月',40,80unionallselect'六月',70,90");Func.DrawingChart("曲线图测试",this.panel1,ds,ChartType.Polygram,0,100,10,"瓦");}注:测试用例内的ds数据请自行写数据库连接,用Sqladapter.Fill填充。
本文档为【C#.NET WinForm 绘制饼图,直方图,曲线图 详细代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
永恒的好天籁
暂无简介~
格式:doc
大小:16KB
软件:Word
页数:25
分类:
上传时间:2022-09-10
浏览量:15