Winform Chart 控件读取datatable后显示图表

时间:2022-05-26 11:06:59
 private void Button2_Click(object sender, EventArgs e)
{
DataTable table = new DataTable();
this.chart1.Series.Clear(); //清空图表中的内容 this.chart1.Titles.Add("Total Income");//添加标题
chart1.DataSource = table;
Series series = this.chart1.Series.Add("LSL");//添加第一个表
series.XValueMember = "Date"; //x轴为时间
series.YValueMembers = "LSL"; //y轴为数据
Series series1 = this.chart1.Series.Add("USL");//添加第二个表
series1.XValueMember = "Date";
series1.YValueMembers = "USL";
this.chart1.Series[].ChartType= SeriesChartType.Spline;//指定图表的类型,这里是折线图
this.chart1.Series[].Color = Color.Blue;
this.chart1.Series[].ChartType = SeriesChartType.Spline;
this.chart1.Series[].Color = Color.Red;
}