您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > c#-ms-chart-控件使用方法汇总(附统计图)
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.AddY(70);series.Points.AddY(60);series.Points.AddY(90);series.Points.AddY(20);//Addseriesintothechart'sseriescollectionchart1.Series.Add(series);同时显示2条曲线//PopulateserieswithrandomdataRandomrandom=newRandom();for(intpointIndex=0;pointIndex10;pointIndex++){Chart1.Series[Series1].Points.AddY(random.Next(45,95));Chart1.Series[Series2].Points.AddY(random.Next(5,75));}//SetseriescharttypeChart1.Series[Series1].ChartType=SeriesChartType.Line;Chart1.Series[Series2].ChartType=SeriesChartType.Spline;//SetpointlabelsChart1.Series[Series1].IsValueShownAsLabel=true;Chart1.Series[Series2].IsValueShownAsLabel=true;//EnableXaxismarginChart1.ChartAreas[ChartArea1].AxisX.IsMarginVisible=true;//Enable3D,andshowdatapointmarkerlinesChart1.ChartAreas[ChartArea1].Area3DStyle.Enable3D=true;Chart1.Series[Series1][ShowMarkerLines]=True;Chart1.Series[Series2][ShowMarkerLines]=True;显示column类型图,柱状图//Createnewdataseriesandsetit'svisualattributesChart1.Series.Clear();Seriesseries=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);series.Points.AddY(20);//Addseriesintothechart'sseriescollectionChart1.Series.Add(series);很多点,效率还可以//FillseriesdatadoubleyValue=50.0;Randomrandom=newRandom();for(intpointIndex=0;pointIndex20000;pointIndex++){yValue=yValue+(random.NextDouble()*10.0-5.0);Chart1.Series[Series1].Points.AddY(yValue);}//SetfastlinecharttypeChart1.Series[Series1].ChartType=SeriesChartType.FastLine;}日期,xy类型//CreateanewrandomnumbergeneratorRandomrnd=newRandom();//DatapointsXvalueisusingcurrentdateDateTimedate=DateTime.Now.Date;//Addpointstothestockchartseriesfor(intindex=0;index10;index++){Chart1.Series[Series1].Points.AddXY(date,//Xvalueisadaternd.Next(40,50));//CloseYvalue//Add1daytoourXvaluedate=date.AddDays(1);}int-int的xy数据绘图//CreateanewrandomnumbergeneratorRandomrnd=newRandom();//Addpointstothestockchartseriesfor(intindex=0;index10;index++){Chart1.Series[Series1].Points.AddXY(rnd.Next(10,90),//Xvalueisadaternd.Next(40,50));//CloseYvalue}数据库数据,datetime-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时间,序号frompub_log_readorderby序号asc;//DataSetds=newDataSet();//OleDbDataAdapterda=newOleDbDataAdapter();//da.SelectCommand=cmd;//da.Fill(ds,tbscore);OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);Chart1.DataBindTable(dr,时间);dr.Close();数据库数据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账号,count(账号)as次数frompub_log_readgroupby账号orderby账号asc;//DataSetds=newDataSet();//OleDbDataAdapterda=newOleDbDataAdapter();//da.SelectCommand=cmd;//da.Fill(ds,tbscore);OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);Chart1.DataBindTable(dr,账号);dr.Close();数据库绑定3-string-int型Chart1.Series.Clear();Chart1.Series.Add(Series1);OleDbConnectionconn=newOleDbConnection(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=newOleDbDataAdapter();da.SelectCommand=cmd;da.Fill(ds,tbscore);Chart1.DataSource=ds;Chart1.Series[Series1].XValueMember=账号;Chart1.Series[Series1].YValueMembers=次数;//DatabindtotheselecteddatasourceChart1.DataBind();conn.Close();数据库4,只绑定yChart1.Series.Clear();Chart1.Series.Add(序号);OleDbConnectionconn=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.SelectCommand=cmd;//da.Fill(ds,tbscore);OleDbDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);Chart1.Series[0].Points.DataBindY(dr);dr.Close();数据库5,绑定xyChart1.Series.Clear();Chart1.Series.Add(序号);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;//Da
本文标题:c#-ms-chart-控件使用方法汇总(附统计图)
链接地址:https://www.777doc.com/doc-4694409 .html