图表
.Net Framework 4及以上有Chart控件,添加 Series是图表中的柱状体的集合,Legends是柱状体的标题批注,Titles是整个图表的标题
修改Series批注
数据源--添加新数据源
添加数据类--项目名称右键添加--LINQ to SQL类--点击资源服务管理器--通过连接的SQL数据库中的表直接拖进DataClass中
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; namespace WindowsFormsApplication5 { public partial class Form1 : Form { public DataClasses1DataContext Context;//数据类1的数据链接文本 public Form1() { InitializeComponent(); Context = new DataClasses1DataContext(); } private void Form1_Load(object sender, EventArgs e) { List<car> list = Context.car.Take(5).ToList(); chart1.DataSource = list; chart1.Series["Series1"].XValueMember = "name"; chart1.Series["Series1"].YValueMembers = "oil"; chart1.Series["Series2"].XValueMember = "name"; chart1.Series["Series2"].YValueMembers = "pailiang"; chart1.Series["Series1"].ChartType = SeriesChartType.FastLine; } } }