Chart控件作图,怎么动态添加Series与ChartAreas
1个回答
2016-01-12
展开全部
using System.Web.UI.DataVisualization.Charting;
private 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;
}
private 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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询