Chart系列(二):数据绑定
2024-08-27 17:18:07
1.绑定到OleDbDataReader:
// Define the database query
string mySelectQuery="SELECT Name, Sales FROM REPS;";
// 。。。。。。
// Create a database reader
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // Since the reader implements and IEnumerable, pass the reader directly into
// the DataBindTable method with the name of the Column to be used as the XValue
Chart1.DataBindTable(myReader, "Name");
2.绑定DataSource
// Define the database query
string mySelectQuery="SELECT * FROM REPS;"; // Create a database connection object using the connection string
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
// Create a database command on the connection using query
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
myConnection.Open();
// set chart data source - the data source must implement IEnumerable
chart1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
// Set series members names for the X and Y values
chart1.Series["Series 1"].XValueMember = "Name";
chart1.Series["Series 1"].YValueMembers = "Sales"; // Data bind to the selected data source
chart1.DataBind();
3.绑定Y值
// Create a database reader
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // Since the reader implements and IEnumerable, pass the reader directly into
// the DataBind method with the name of the Column selected in the query
chart1.Series["Default"].Points.DataBindY(myReader, "GrossSales");
4.绑定X和Y
// Create a database reader
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // Since the reader implements IEnumerable, pass the reader directly into
// the DataBind method with the name of the Column selected in the query
chart1.Series["Default"].Points.DataBindXY(myReader, "Name", myReader, "Sales");
最新文章
- 建模元件有哪些在MapleSim中
- entity framework 5 批量增删改效率优化
- 简单使用AutoMapper实现DTO转换
- 【JavaScript】JS_Object跟Function的区别
- Python 实现粒子滤波
- quartus II PIN脚相关之一
- 高性能的数据压缩库libzling
- Google Appengine参考路径
- JPA---一对一关系
- 画画 保存为图片 MaskFilter 边缘效果
- 菜鸟进阶Android Touch事件传递(四)
- 山谈c中printf格式修饰符
- R语言重要数据集分析研究——需要整理分析阐明理念
- iOS libyuv
- OpenCV+TensorFlow实现自定义手写图像识别
- idea 中dao层自动生成接口
- 关键词提取_tf_idf
- 【面试】iOS 开发面试题(二)
- mysql出现1030 Got error 28 from storage engine解决方法
- Volley 解析