0
這是我第一次接觸數據綁定,所以我對所涉及的所有屬性和方法知之甚少。我想將多個系列綁定到csv文件,其中列1是DateTime,列2到N是雙打。我從WinFormsChartSamples中的示例開始,將單個Y值綁定到csv;但是,不要相信我理解綁定多個Y值的方式。C#Windows窗體圖表控件 - 綁定csv文件中的多個y值
原始代碼:
string mySelectQuery = "Select * from " + file;
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
path + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\"";
OleDbConnection myConnection = new OleDbConnection(ConStr);
// create a database command on the connection using query
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
// open the connection
myCommand.Connection.Open();
// create a database reader
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
// column 1 is a time value, column 2 is a double
// databind the reader to the chart using the DataBindXY method
chart1.Series[0].Points.DataBindXY(myReader, "1", myReader, "2");
以下工作:
myCommand.Connection.Open();
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
chart1.Series[0].Points.DataBindXY(myReader, "1", myReader, "2");
myCommand.Connection.Open();
myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
chart1.Series[1].Points.DataBindXY(myReader, "1", myReader, "3");
myCommand.Connection.Open();
myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
chart1.Series[2].Points.DataBindXY(myReader, "1", myReader, "4");
我可以把上面成一個循環,並遍歷所有系列的,但肯定有一個更好的辦法比通過多次讀取csv文件?