图表
private void Form1_Load(object sender, EventArgs e) { //前提: //先添加一个DataClasser.dbml文件,然后DataClasser.dbml文件中点击视图中的服务器资源管理器选择数据库,选完数据库后点击 //数据连接下属的表,然后将表拖到DataClasser.dbml文件中 DataClasses1DataContext context = new DataClasses1DataContext(); //造一个用来连接数据库的类 List<car> list = context.car.Take(5).ToList(); //将查询到的结果反馈到一个list泛型集合 ---Take(5)是选择只显示5个 chart1.DataSource = list;//图表1的数据源为list chart1.Series["Series1"].XValueMember = "Name";//绑定X轴 chart1.Series["Series1"].YValueMembers = "Oil";//绑定Y轴 //chart1.Series["Series"].ChartType=System.Windows.Forms chart1.Series["Series2"].XValueMember = "Name";//绑定X轴 chart1.Series["Series2"].YValueMembers = "Price";//绑定Y轴 }