zoukankan      html  css  js  c++  java
  • Chart系列(二):数据绑定

    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");

    image

    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();

    image

    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");

    image

    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");

    image

  • 相关阅读:
    POJ-2387-Til the Cows Come Home 解题报告
    编程能力与编程年龄
    POJ-1703-Find them, Catch them 解题报告
    科学计算和可视化
    判断素数
    余初闻回文数,初试函数解,竟成!(指出前n个回文素数)
    经典题:*年*月*日是第几天
    验证码的校验
    天天向上的力量终于好了!!
    阶乘
  • 原文地址:https://www.cnblogs.com/pengzhen/p/4082435.html
Copyright © 2011-2022 走看看