版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、c#mschart控件使用方法第一個簡單的chart:創(chuàng)建曲線圖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數(shù)據(jù)繪圖/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();數(shù)據(jù)庫數(shù)據(jù),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);數(shù)據(jù)庫數(shù)據(jù)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次數(shù)frompub_log_readgroupby貝長號orderby賬號asc;/DataSetds=newDataSet();/OleDbDataAdapterda=newOleDbDataAdapter();/da.SelectCommand=cmd;/da.Fill(ds,tbscore);次數(shù)次數(shù)323232324324323S9323243243232432323432+432adni數(shù)據(jù)庫綁定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次數(shù)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=次數(shù);/DatabindtotheselecteddatasourceChart1.DataBind();conn.Close();次數(shù)次數(shù)OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection)OleDbDataReaderdr=cm
16、d.ExecuteReader(CommandBehavior.CloseConnection);Chartl.Series0.Points.DataBindY(dr);dr.Close();323232324324323S9323243243232432323432+432adni數(shù)據(jù)庫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);數(shù)據(jù)庫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次數(shù)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,次數(shù)”);dr.Close();序號序號324324323993323232adni323432443223243243232432數(shù)據(jù)庫6,支持顯示參數(shù)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();王五張三李強個中數(shù)據(jù)庫7,支持多l(xiāng)ineChart1.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數(shù)據(jù)庫8,按照行添加數(shù)據(jù)/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數(shù)據(jù)/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數(shù)據(jù)/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數(shù)據(jù)/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();數(shù)組繪圖/Initializeanarrayofdoublesdoubleyval=2,6,4,5,3;/Initializeanarrayofstringsstringxval=Peter,Andre
37、w,Julie,Mary,Dave;/BindthedoublearraytotheYaxispointsoftheDefaultdataseriesChart1.SeriesSeries1.Points.DataBindXY(xval,yval);數(shù)據(jù)庫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();指定坐標軸的數(shù)據(jù)顯示范圍/C
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2030年中國鋼結構行業(yè)運行態(tài)勢及需求趨勢預測報告
- 2024-2030年中國金融服務外包行業(yè)全景調研與發(fā)展戰(zhàn)略研究咨詢報告
- 2024-2030年中國金屬采礦行業(yè)投資策略與可持續(xù)發(fā)展建議報告
- 2024-2030年中國金冶煉市場經(jīng)營規(guī)模與營銷策略展望研究報告
- 2024-2030年中國重氮化合物行業(yè)發(fā)展態(tài)勢及產(chǎn)銷規(guī)模預測報告
- 2024-2030年中國醚后碳四市場銷售規(guī)模與未來前景盈利性研究報告
- 2024-2030年中國酸廢氣凈化器市場運行態(tài)勢及競爭格局分析報告版
- 2024-2030年中國酚醛胺固化劑市場運營態(tài)勢與投資策略深度研究報告
- 2024-2030年中國鄰異丙基酚市場需求規(guī)模及發(fā)展現(xiàn)狀調研報告
- 2024-2030年中國透明皂市場競爭力剖析與投資價值評估報告
- (高清版)JTGT D81-2017 公路交通安全設施設計細則
- 孤獨癥集體課培訓
- 淚小管斷裂的護理查房
- 國家安全法課件
- 小學四年級上冊《常見的數(shù)量關系》市公開課一等獎省賽課獲獎課件
- 人教版物理八年級上冊第六章質量和密度大單元整體教學設計
- 金融知識校園宣傳課件
- (高清版)DZT 0305-2017 天然場音頻大地電磁法技術規(guī)程
- 2024年江蘇蘇州大學招聘專職輔導員42人歷年高頻考題難、易錯點模擬試題(共500題)附帶答案詳解
- 大風天氣的應急預案
- 【川教版】《生命 生態(tài) 安全》六上第17課《舌尖上的四川》課件
評論
0/150
提交評論