【问题标题】:Fast Plotting in MSCharts with C#使用 C# 在 MSCharts 中快速绘图
【发布时间】:2014-10-31 13:21:48
【问题描述】:

我需要使用 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%)...

我怎样才能以更快、更有效的方式做到这一点?

【问题讨论】:

  • 考虑到常见的显示是 60 Hz > 16 ms / 帧,每 1 ms 更新一次图表没有多大意义。无论如何,我怀疑您能否在 C#/.NET 中使用 MS Chart 获得您所要求的性能。
  • 是的,这会有所不同,因为我看不到该频率的数据并不重要,但我需要编程以继续以 1 KHz 的频率采集数据...谢谢
  • 是不是不能以 1 KHz 获取和处理数据而以 60Hz 进行渲染和显示?
  • 是的,但仍然很慢......我的问题是,有没有比使用 AddXY() 更有效的方法来绘制 X 和 Y 数组?

标签: c# winforms visual-studio-2010 mschart


【解决方案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 项目。
它可能比遍历数据集更快。

我建议你下载Samples Environments for Microsoft Chart Controls

【讨论】:

  • 如果您提到 Microsoft 图表控件的示例环境,我希望我能给您 +100.... 谢谢,非常感谢!
猜你喜欢
  • 2010-12-06
  • 2015-06-21
  • 1970-01-01
  • 1970-01-01
  • 2015-04-30
  • 2015-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多