wpf WPF实时图表应用架构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19452935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:53:55  来源:igfitidea点击:

WPF realtime chart application architecture

c#wpfchartsprism

提问by user2799180

I have the following scenario in mind:

我想到了以下场景:

I want to send (via serial port) some commands to a device. This device does send me back a continuous stream of data (max. 12000 values per second).

我想(通过串行端口)向设备发送一些命令。该设备确实向我发送了连续的数据流(每秒最多 12000 个值)。

To control some settings I need some buttons to send commands to the device to start/stop/change settings before and during data stream. Also I want to have a real time plot of this data. I will filter this data of course. Also at certain timestamps there will be a signal which indicates that I want to cut out a certain window of the received data.

为了控制某些设置,我需要一些按钮来向设备发送命令以在数据流之前和期间启动/停止/更改设置。我也想有这个数据的实时图。我当然会过滤这些数据。同样在某些时间戳处,会有一个信号表明我想切出接收数据的某个窗口。

This means I will have two charts. I made already some progress using WPF but now when I interact (zoom/pan) with the lower chart, the upper one freezes noticeable. This is because both have do be refreshed very often!

这意味着我将有两个图表。我已经使用 WPF 取得了一些进展,但是现在当我与下方图表交互(缩放/平移)时,上方图表明显冻结。这是因为两者都经常刷新!

Work (data receiving/filtering) is done using threads but the update of the plot has to be done within the ui thread.

工作(数据接收/过滤)是使用线程完成的,但绘图的更新必须在 ui 线程中完成。

Any ideas how to solve this issue? Maybe using multiple processes?

任何想法如何解决这个问题?也许使用多个进程?

enter image description here

在此处输入图片说明

回答by philologon

You should use Reactive Extensions. It was built for this kind of thing.

您应该使用反应式扩展。它是为这种事情而建造的。

http://msdn.microsoft.com/en-us/data/gg577609.aspx

http://msdn.microsoft.com/en-us/data/gg577609.aspx

Requesting a clear, picturesque explanation of Reactive Extensions (RX)?

要求对 Reactive Extensions (RX) 进行清晰、如画的解释?

On this second link, although the topic is javascript, much of what it says is about Reactive Extensions and cross-applies to Rx in C#.

在第二个链接上,虽然主题是 javascript,但它所说的大部分内容都是关于 Reactive Extensions 和交叉适用于 C# 中的 Rx。

回答by MrZoidberg

I'm making a similar WPF application with real-time waveforms (about 500Hz). I have a background threads that receives real-time data, a separate threads to process them and prepare the data for drawing (I have a buffer with the "size" of the screen where I put the prepared values). In the UI thread I draw the waveforms to the RenderTargetBitmapwhich is in the end is rendered to the Canvas. This technique allows me have a lot of real-time waveforms on the screen and have zoom and pan working without any problems (about 40-50 fps).

我正在使用实时波形(约 500Hz)制作类似的 WPF 应用程序。我有一个接收实时数据的后台线程,一个单独的线程来处理它们并准备绘制数据(我有一个缓冲区,其中包含我放置准备好的值的屏幕“大小”)。在 UI 线程中,我将波形绘制到RenderTargetBitmap,最终渲染到 Canvas。这种技术让我在屏幕上有很多实时波形,并且可以毫无问题地进行缩放和平移(大约 40-50 fps)。

Please let me know if you need some technical details, I can later share them with you.

如果您需要一些技术细节,请告诉我,我稍后可以与您分享。

I think you have some code in the UI thread that is not optimized well or can be moved to the background thread.

我认为您在 UI 线程中有一些代码没有优化好或者可以移动到后台线程。

Btw, do you use any framework for charts?

顺便说一句,您是否使用任何图表框架?

Edit

编辑

philologonis right, you should use Rx for real-time data, it simplifies code A LOT. I also use them in my project.

philologon是对的,您应该将 Rx 用于实时数据,它简化了很多代码。我也在我的项目中使用它们。

回答by Dr. ABT

Its a commercial product but there is a real-time WPF chart which can handle this use-case and then some. Please take a look at the Tutorial below:

它是一个商业产品,但有一个实时 WPF 图表可以处理这个用例,然后是一些。请看下面的教程:

http://www.scichart.com/synchronizing-chartmodifier-mouse-events-across-charts/

http://www.scichart.com/synchronizing-chartmodifier-mouse-events-across-charts/

enter image description here

在此处输入图片说明

There is a live Silverlight demo of this behaviour here:

此处有此行为的实时 Silverlight 演示:

Sync Multichart Mouse Silverlight Demo

同步多图表鼠标 Silverlight 演示

And this chart should be able to handle zooming while inputting values at high speed:

并且此图表应该能够在高速输入值时处理缩放:

Realtime Performance Demo

实时性能演示

Disclosure:I am the owner and tech-lead of SciChart

披露:我是 SciChart 的所有者和技术负责人