Label lb1=new Label()
this.add(lb1) //如果没有这行,标签lb1就“看不见”,this是窗体
所以vs2005“动态添加的控件”是两个步骤: 1.动态生成 2.添加
using System.Web.UI.DataVisualization.Chartingprivate void NewChart()
{
Chart Chart1=new Chart1
//设置位置
Chart .Location = new System.Drawing.Point(83, 120)
DataTable dt = CreateDataTable()
//设置图表的数据源
Chart1.DataSource = dt
//设置图表Y轴对应项
Chart1.Series[0].YValueMembers = "Time"
//设置图表X轴对应项
Chart1.Series[0].XValueMember = "Date"
//绑定数据
Chart1.DataBind()
}
//创建表
private DataTable CreateDataTable()
{
DataTable dt = new DataTable()
//添加列
dt.Columns.Add("Date")
dt.Columns.Add("Time")
DataRow dr
//添加行dr = dt.NewRow()
dr["Date"] = "2010-1-1"
dr["Time"] = "10:12"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr["Date"] = "2010-1-2"
dr["Time"] = "10:11"
dt.Rows.Add(dr)
return dt
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)