public void load()
{
//图表区域
ChartArea chartArea = new ChartArea();
//用于显示线条名称,在右侧显示线条名称
Legend legend = new Legend();
//给图表区域赋值名字
chartArea.Name = "chartArea";
legend.Name = "legend";
//实例化一条数据线
Series date = new Series();
//类型设置为折线图
date.ChartType = SeriesChartType.Spline;
//设置区域
date.ChartArea = "chartArea";
//设置名字
date.Legend = "legend";
//宽度
date.MarkerBorderWidth = 2;
//大小
date.MarkerSize = 4;
//数据点(表现形式,点的样式)
date.MarkerStyle = MarkerStyle.Circle;
//数据
List<int> x = new List<int>() { 1, 2, 3, 4, 5 };
List<int> l1 = new List<int>() { 10, 20, 30, 40, 50 };
//数据赋值xy两个值
date.Points.DataBindXY(x, l1);
//实例化一个图标chart
Chart chart = new Chart();
//取名
chart.Name = "chart";
//定制坐标
chart.Location = new Point(50, 50);
chart.Text = "chart";
//添加数据线到图表
chart.Series.Add(date);
//设置图表的区域,ps:图表不设置区域会默认显示为白色的一块
chart.ChartAreas.Add(chartArea);
//添加数据名称
chart.Legends.Add(legend);
//将图表添加到页面上
Controls.Add(chart);
}
}