版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、c#mschart控件使用方法第一个简单的chart:创建曲线图chart1.Series.Clear();Seriesseries=newSeries(Spline);series.ChartType=SeriesChartType.Spline;series.BorderWidth=3;series.ShadowOffset=2;/Populatenewserieswithdataseries.Points.AddY(67);series.Points.AddY(57);series.Points.AddY(83);series.Points.AddY(23);series.Points.
2、AddY(70);series.Points.AddY(60);series.Points.AddY(90);series.Points.AddY(20);/Addseriesintothechartsseriescollectionchart1.Series.Add(series);Chart1.SeriesSeries1.Points.AddY(random.Next(45,95);Chart1.SeriesSeries2.Points.AddY(random.Next(5,75);/SetseriescharttypeChart1.SeriesSeries1.ChartType=Seri
3、esChartType.Line;Chart1.SeriesSeries2.ChartType=SeriesChartType.Spline;/SetpointlabelsChart1.SeriesSeries1.IsValueShownAsLabel=true;Chart1.SeriesSeries2.IsValueShownAsLabel=true;/EnableXaxismarginChart1.ChartAreasChartArea1.AxisX.IsMarginVisible=true;/Enable3D,andshowdatapointmarkerlinesChart1.Chart
4、AreasChartArea1.Area3DStyle.Enable3D=true;Chart1.SeriesSeries1ShowMarkerLines=True;Chart1.SeriesSeries2ShowMarkerLines=True;ss1Q07165&556151504532222斗6810915749ss1Q07165&556151504532222斗6810915749Series1Series2显示column类型图,柱状图/CreatenewdataseriesandsetitsvisualattributesChart1.Series.Clear();Seriesse
5、ries=newSeries(FlowRead);series.ChartType=SeriesChartType.Column;series.BorderWidth=3;series.ShadowOffset=2;/Populatenewserieswithdataseries.Points.AddY(67);series.Points.AddY(57);series.Points.AddY(83);series.Points.AddY(23);series.Points.AddY(70);series.Points.AddY(60);series.Points.AddY(90);serie
6、s.Points.AddY(20);/AddseriesintothechartsseriescollectionChart1.Series.Add(series);FIcwReadFIcwRead很多点,效率还可以/FillseriesdatadoubleyValue=50.0;Randomrandom=newRandom();for(intpointIndex=0;pointIndex20000;pointIndex+)yValue=yValue+(random.NextDouble()*10.0-5.0);Chart1.SeriesSeries1.Points.AddY(yValue);
7、/SetfastlinecharttypeChart1.SeriesSeries1.ChartType=SeriesChartType.FastLine;日期,xy类型/CreateanewrandomnumbergeneratorRandomrnd=newRandom();/DatapointsXvalueisusingcurrentdateDateTimedate=DateTime.Now.Date;/Addpointstothestockchartseriesfor(intindex=0;index10;index+)Chart1.SeriesSeries1.Points.AddXY(d
8、ate,/Xvalueisadaternd.Next(40,50);/CloseYvalue/Add1daytoourXvaluedate=date.AddDays(1);int-int的xy数据绘图/CreateanewrandomnumbergeneratorRandomrnd=newRandom();/Addpointstothestockchartseriesfor(intindex=0;index10;index+)Chart1.SeriesSeries1.Points.AddXY(rnd.Next(10,90),/Xvalueisadaternd.Next(40,50);/Clos
9、eYvalueOleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);Chart1.DataBindTable(dr,时间);dr.Close();OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);OleDbDataReaderdr=cmd.ExecuteReader(CommandBeha
10、vior.CloseConnection);Chart1.DataBindTable(dr,时间);dr.Close();OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);Chart1.DataBindTable(dr,时间);dr.Close();数据库数据,datetime-int类型Chart1.Series.Clear();OleDbConnectionconn=
11、newOleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+Application.StartupPath+db.mdb+;PersistSecurityInfo=False);OleDbCommandcmd=conn.CreateCommand();conn.Open();cmd.CommandText=select时间,序号frompub_log_readorderby序号asc;/DataSetds=newDataSet();/OleDbDataAdapterda=newOleDbDataAdapter();/da.Se
12、lectCommand=cmd;/da.Fill(ds,tbscore);数据库数据2,string-int类型Chart1.Series.Clear();OleDbConnectionconn=newOleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+Application.StartupPath+db.mdb+;PersistSecurityInfo=False);OleDbCommandcmd=conn.CreateCommand();conn.Open();cmd.CommandText=select贝长号,coun
13、t(账号)as次数frompub_log_readgroupby贝长号orderby账号asc;/DataSetds=newDataSet();/OleDbDataAdapterda=newOleDbDataAdapter();/da.SelectCommand=cmd;/da.Fill(ds,tbscore);次数次数323232324324323S9323243243232432323432+432adni数据库绑定3-string-int型Chart1.Series.Clear();Chart1.Series.Add(Series1);OleDbConnectionconn=newOle
14、DbConnection(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+Application.StartupPath+db.mdb+;PersistSecurityInfo=False);OleDbCommandcmd=conn.CreateCommand();cmd.CommandText=select贝长号,count(账号)as次数frompub_log_readgroupby贝长号orderby账号asc;conn.Open();DataSetds=newDataSet();OleDbDataAdapterda=newOleDbDataAd
15、apter();da.SelectCommand=cmd;da.Fill(ds,tbscore);Chart1.DataSource=ds;Chart1.SeriesSeries1.XValueMember=账号;Chart1.SeriesSeries1.YValueMembers=次数;/DatabindtotheselecteddatasourceChart1.DataBind();conn.Close();次数次数OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection)OleDbDataReaderdr=cm
16、d.ExecuteReader(CommandBehavior.CloseConnection);Chartl.Series0.Points.DataBindY(dr);dr.Close();323232324324323S9323243243232432323432+432adni数据库4,只绑定yChart1.Series.Clear();Chartl.Series.Add(序号);OleDbConnectionconn=newOleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+Application.StartupPa
17、th+db.mdb+;PersistSecurityInfo=False);OleDbCommandcmd=conn.CreateCommand();conn.Open();cmd.CommandText=select序号frompub_log_readorderby序号asc;/DataSetds=newDataSet();/OleDbDataAdapterda=newOleDbDataAdapter();/da.SelectCommand=cmd;/da.Fill(ds,tbscore);数据库5,绑定xyChart1.Series.Clear();Chartl.Series.Add(序号
18、);OleDbConnectionconn=newOleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+Application.StartupPath+db.mdb+;PersistSecurityInfo=False);OleDbCommandcmd=conn.CreateCommand();conn.Open();cmd.CommandText=select贝长号,count(账号)as次数frompub_log_readgroupby贝长号orderby账号desc;/DataSetds=newDataSet();/Ol
19、eDbDataAdapterda=newOleDbDataAdapter();/da.SelectCommand=cmd;/da.Fill(ds,tbscore);OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);Chartl.Series0.Points.DataBindXY(dr,账号”,dr,次数”);dr.Close();序号序号324324323993323232adni323432443223243243232432数据库6,支持显示参数Chart1.Series.Clear();Chart1.
20、Series.Add(S1);OleDbConnectionconn=newOleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+Application.StartupPath+db.mdb+;PersistSecurityInfo=False);OleDbCommandcmd=conn.CreateCommand();conn.Open();cmd.CommandText=SELECT*FROMREPSALESWHEREYear=2004;/DataSetds=newDataSet();/OleDbDataAdapterda
21、=newOleDbDataAdapter();/da.SelectCommand=cmd;/da.Fill(ds,tbscore);OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);Chart1.Series0.Points.DataBind(dr,name,sales,Tooltip=Year,Label=CommissionsC2);dr.Close();王五张三李强个中数据库7,支持多lineChart1.Series.Clear();Chart1.Series.Add(S1);OleDbConnec
22、tionconn=newOleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+Application.StartupPath+db.mdb+;PersistSecurityInfo=False);OleDbCommandcmd=conn.CreateCommand();conn.Open();cmd.CommandText=SELECT*FROMREPSALES;/DataSetds=newDataSet();/OleDbDataAdapterda=newOleDbDataAdapter();/da.SelectCommand
23、=cmd;/da.Fill(ds,tbscore);OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);Chart1.DataBindCrossTable(dr,Name,Year,Sales,Label=CommissionsC);dr.Close();35QQD3000025QQD20QOG1500035QQD3000025QQD20QOG15000WOOD50003.SS3LP止UUIr*+23?2UTL,Jidinnn;r3J2TD,DZ.32B8201220142013020022004200620
24、03201020032005200720092011数据库8,按照行添加数据/ResolvetheaddresstotheAccessdatabasestringfileNameString=this.MapPath(.);fileNameString+=.datachartdata.mdb;/InitializeaconnectionstringstringmyConnectionString=PROVIDER=Microsoft.Jet.OLEDB.4.0;DataSource=+fileNameString;/DefinethedatabasequerystringmySelectQue
25、ry=SELECT*FROMSALESCOUNTS;/CreateadatabaseconnectionobjectusingtheconnectionstringOleDbConnectionmyConnection=newOleDbConnection(myConnectionString);/CreateadatabasecommandontheconnectionusingqueryOleDbCommandmyCommand=newOleDbCommand(mySelectQuery,myConnection);/OpentheconnectionmyCommand.Connectio
26、n.Open();/InitializesanewinstanceoftheOleDbDataAdapterclassOleDbDataAdaptermyDataAdapter=newOleDbDataAdapter();myDataAdapter.SelectCommand=myCommand;/InitializesanewinstanceoftheDataSetclassDataSetmyDataSet=newDataSet();/AddsrowsintheDataSetmyDataAdapter.Fill(myDataSet,Query);foreach(DataRowrowinmyD
27、ataSet.TablesQuery.Rows)/ForeachRowaddanewseriesstringseriesName=rowSalesRep.ToString();Chart1.Series.Add(seriesName);Chart1.SeriesseriesName.ChartType=SeriesChartType.Line;Chart1.SeriesseriesName.BorderWidth=2;for(intcolIndex=1;colIndexmyDataSet.TablesQuery.Columns.Count;colIndex+)/Foreachcolumn(co
28、lumn1andonward)addthevalueasapointstringcolumnName=myDataSet.TablesQuery.ColumnscolIndex.ColumnName;intYVal=(int)rowcolumnName;Chart1.SeriesseriesName.Points.AddXY(columnName,YVal);DataGrid.DataSource=myDataSet;DataGrid.DataBind();/Closestheconnectiontothedatasource.Thisisthepreferred/methodofclosin
29、ganyopenconnection.myCommand.Connection.Close();使用xml数据/resolvetheaddresstotheXMLdocumentstringfileNameString=this.MapPath(.);stringfileNameSchema=this.MapPath(.);fileNameString+=.datadata.xml;fileNameSchema+=.datadata.xsd;/InitializesanewinstanceoftheDataSetclassDataSetcustDS=newDataSet();/ReadXMLs
30、chemaintotheDataSet.custDS.ReadXmlSchema(fileNameSchema);/ReadXMLschemaanddataintotheDataSet.custDS.ReadXml(fileNameString);/InitializesanewinstanceoftheDataViewclassDataViewfirstView=newDataView(custDS.Tables0);/SincetheDataViewimplementsandIEnumerable,passthereaderdirectlyinto/theDataBindTablemeth
31、odwiththenameofthecolumnusedfortheXvalue.Chart1.DataBindTable(firstView,Name);使用excel数据/resolvetheaddresstotheExcelfilestringfileNameString=this.MapPath(.);fileNameString+=.dataExcelData.xls;/Createconnectionobjectbyusingtheprecedingconnectionstring.stringsConn=Provider=Microsoft.Jet.OLEDB.4.0;DataS
32、ource=+fileNameString+;ExtendedProperties=Excel8.0;HDR=YES;OleDbConnectionmyConnection=newOleDbConnection(sConn);myConnection.Open();/ThecodetofollowusesaSQLSELECTcommandtodisplaythedatafromtheworksheet./CreatenewOleDbCommandtoreturndatafromworksheet.OleDbCommandmyCommand=newOleDbCommand(Select*From
33、data1$A1:E25,myConnection);/createadatabasereaderOleDbDataReadermyReader=myCommand.ExecuteReader(CommandBehavior.CloseConnection);/PopulatethechartwithdatainthefileChart1.DataBindTable(myReader,HOUR);/closethereaderandtheconnectionmyReader.Close();myConnection.Close();使用csv数据/FilenameoftheCSVfilestr
34、ingfile=DataFile.csv;/GetthepathoftheCSVfilestringpath=this.MapPath(.);path+=.data;/Createaselectstatementandaconnectionstring.stringmySelectQuery=Select*from+file;stringConStr=Provider=Microsoft.Jet.OLEDB.4.0;DataSource=+path+;ExtendedProperties=Text;HDR=No;FMT=Delimited;OleDbConnectionmyConnection
35、=newOleDbConnection(ConStr);/CreateadatabasecommandontheconnectionusingqueryOleDbCommandmyCommand=newOleDbCommand(mySelectQuery,myConnection);/OpentheconnectionandcreatethereadermyCommand.Connection.Open();OleDbDataReadermyReader=myCommand.ExecuteReader(CommandBehavior.CloseConnection);/Column1isati
36、mevalue,column2isadouble/DatabindthereadertothechartusingtheDataBindXYmethodChart1.Series0.Points.DataBindXY(myReader,1,myReader,2);/CloseconnectionanddatareadermyReader.Close();myConnection.Close();数组绘图/Initializeanarrayofdoublesdoubleyval=2,6,4,5,3;/Initializeanarrayofstringsstringxval=Peter,Andre
37、w,Julie,Mary,Dave;/BindthedoublearraytotheYaxispointsoftheDefaultdataseriesChart1.SeriesSeries1.Points.DataBindXY(xval,yval);数据库9,dataview/ResolvetheaddresstotheAccessdatabasestringfileNameString=this.MapPath(.);fileNameString+=.datachartdata.mdb;/InitializeaconnectionstringstringmyConnectionString=
38、PROVIDER=Microsoft.Jet.OLEDB.4.0;DataSource=+fileNameString;/DefinethedatabasequerystringmySelectQuery=SELECT*FROMREPS;/CreateadatabaseconnectionobjectusingtheconnectionstringOleDbConnectionmyConnection=newOleDbConnection(myConnectionString);/CreateadatabasecommandontheconnectionusingqueryOleDbComma
39、ndmyCommand=newOleDbCommand(mySelectQuery,myConnection);/OpentheconnectionmyCommand.Connection.Open();/InitializesanewinstanceoftheOleDbDataAdapterclassOleDbDataAdaptercustDA=newOleDbDataAdapter();custDA.SelectCommand=myCommand;/InitializesanewinstanceoftheDataSetclassDataSetcustDS=newDataSet();/Add
40、srowsintheDataSetcustDA.Fill(custDS,Customers);/InitializesanewinstanceoftheDataViewclassDataViewfirstView=newDataView(custDS.Tables0);/SincetheDataViewimplementsIEnumerable,passthedataviewdirectlyinto/theDataBindmethodwiththenameoftheColumnsselectedinthequeryChart1.SeriesDefault.Points.DataBindXY(firstView,Name,firstView,Sales);/Closestheconnectiontothedatasource.Thisisthepreferred/methodofclosinganyopenconnection.myCommand.Connection.Close();指定坐标轴的数据显示范围/C
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 04版自建房施工工程维护合同
- 2024年度0kv输变电工程维修保养合同
- 透镜在物理教学中的应用方案研究
- 2024年度保险合同
- 大型活动垃圾清运专项方案
- 2024年GRC技术转让合同
- 2024年建筑材料购销合同范本
- 塔吊安装质量保证合同
- 幼儿园心理咨询微信平台管理
- 2024年建筑行业冠梁工程合同
- 上海市交大附中附属嘉定德富中学2024-2025学年九年级上学期期中考数学卷
- 屠宰场食品安全管理制度
- 部编版(2024秋)语文一年级上册 6 .影子课件
- 2024秋期国家开放大学专科《刑事诉讼法学》一平台在线形考(形考任务一至五)试题及答案
- 基于SICAS模型的区域农产品品牌直播营销策略研究
- 病例讨论英文
- 2024秋期国家开放大学专科《液压与气压传动》一平台在线形考(形考任务+实验报告)试题及答案
- 【课件】植物体的结构层次课件-2024-2025学年人教版生物七年级上册
- 24秋国家开放大学《0-3岁婴幼儿的保育与教育》期末大作业参考答案
- 相对湿度计算公式
- 2024版肿瘤患者静脉血栓防治指南解读 课件
评论
0/150
提交评论