绘制数据太慢 [英] plotting data is too slow

查看:121
本文介绍了绘制数据太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图用c#创建一个示波器类型的程序,该程序可以以很高的速度绘制数据点.使用标准绘图工具,我创建了一个应用,该应用以行进波形尽可能快地绘制750个2位随机数的图形.这是我使用的一些代码:

So I''m trying to create an oscilloscope type program in c# which can plot data points at very high speeds. Using the standard plotting tool, I created an application that graphs 750 2-digit random numbers as fast as possible, with a traveling waveform. Here is some code I use:

dt = new DataTable();
 dc = new DataColumn();
 dc.ColumnName = "Time"; // x-axis title;
 dt.Columns.Add(dc);
 dc = new DataColumn();
 dc.ColumnName = "Score"; // y-axis title
 dt.Columns.Add(dc);

     for (int i = 0; i < 750; i++)
     {

         Random r = new Random();
         DataRow dr;//add rows
         dr = dt.NewRow();
         dr["Time"] = index;
         dr["Score"] = r.Next(10, 99);
         dt.Rows.Add(dr);

         if (index >= 30)
         {
             DataRow rowRemoved = dt.Rows[0];
             dt.Rows.Remove(rowRemoved);
         }

         dataGridView1.DataSource = dt;
         chart1.DataSource = dt;
         chart1.Series["Series1"].XValueMember = "Time";
         chart1.Series["Series1"].YValueMembers = "Score";
         chart1.DataBind();

         index++;

         Application.DoEvents();
     }


我知道Application.DoEvents()似乎总是被皱着眉头,但是我使用它是为了中断线程,以便可以看到生成的每个点的波形.绘制750点需要花费近30秒的时间.我的最终目标是在1秒内绘制1000点.有什么建议吗?

谢谢
GabeA


I know that Application.DoEvents() always seems to be frowned upon, but I use it in order to interrupt the thread so that I can see the waveform every point that is generated. It takes almost 30 seconds to graph 750 points. My ultimate goal is to graph 1000 points in 1 second. Any suggestions?

Thanks
GabeA

推荐答案

我不确定该图表是否能够快速完成此类任务.我建议您尝试使用其他图表,并对性能进行一些测试并评估您的要求.
I''m not sure if that charts are built to do that kind of tasks very fast. I''ll suggest you to try to use another charts, and make some test with performance and evaluate your requirements.


我认为主要的问题是您进行了过多的操作在循环中.

您在每次迭代中都调用chart1.DataBind()Application.DoEvents(),这将使您的应用程序变得非常慢.

通常,使用Application.DoEvents()没有多大意义.对于示波器来说,使用计时器并在每次计时器触发时更新图表会更有意义.
I would think that the main problem is that you do too much long operation inside the loop.

You are calling chart1.DataBind() and Application.DoEvents() on each iteration whichy will make you application deadly slow as it is.

Generally, it make not much sense to use Application.DoEvents(). For an oscilloscope, it would make more sense to use a timer and update the chart each time the timer fire.


因此,我建议尝试简单"优化之后,您可以尝试从其他供应商处下载图表并测试其性能.您可能会从他们在他们的网站上获得的样本中得到很好的提示.

您还可以尝试一些WPF图表(硬件加速).

最后,特别是使用计时器"替代方法,您可以简单地合并一些刷新.假设您对15 fps感到满意,那么您可能有一个计时器,该计时器每65毫秒左右一次滴答,并添加自上次更新以来收到的所有点.

此方法的优点是,当计算机电量不足时,它将以某种方式自动根据计算机的速度(或负载)进行调整.因此,缓慢的计算机迁移会为每次刷新添加3个新点,并平均删除3个旧点.
Thus, I would suggest that after having tried "easy" optimizations, that you try to download charts from other vendors and test their performance. You might have a good hint from the sample they have on thier web site.

You might also try some WPF charts (hardware accelerated).

Finally and particulary with the "timer" alternative, you might simply merge a few refresh. Say that you would be satisfied with 15 fps, then you might have a timer that tick every 65 milliseconds or so and add all points received since last update.

The advantage of this method is that it would somehow automatically adjust with the computer speed (or load) when the computer has not enough power. Thus a slow computer migth add 3 new points and remove 3 old points (on average) for each refresh.


这篇关于绘制数据太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆