我需要使用C#每1毫秒更新MS图表中的FastLine图。我有两个2048个元素的数组,一个用于X值(xValue
),另一个用于Y值(yValue
)。目前我这样做:
chart1.Series[0].Points.Clear();
for (int i = 0; i < 2048; i++)
{
chart1.Series[0].Points.AddXY(xValue[i], yValue[i]);
}
问题是这很慢(我需要速度的5%)......
如何以更快,更有效的方式实现?
答案 0 :(得分:1)
你有没有试过这样的事情:
// initialize a connection string
string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;
// define the database query
string mySelectQuery="SELECT Name, Sales FROM REPS WHERE RegionID < 3;";
// 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);
// open the connection
myCommand.Connection.Open();
// 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.DataBindXY(myReader, "Name", myReader, "Sales");
这是直接从DatabaseBindingXY.cs中的MSChart项目获取的 它可能比循环遍历数据集更快。