我正在考虑使用 wxMathPlot 来绘制/绘制一些连续到达的数据。 我想用它来绘制“实时”绘图/图表。 那可能吗?
IE 我不想要一次性读取文件的静态图 - 我想要绘制流数据并继续到图的右侧 - (并让左侧脱落/滚动到视图之外)
编辑
我仍然没有得到答案。 wxmathPlot 库中有一个有趣的类,称为 mpFXYVector,但它似乎只是从数据向量中绘制一个图。 我想要的是可以输入流并水平滚动图表的东西(如果需要的话还可以调整比例大小)
I am thinking of using wxMathPlot for plotting/graphing some data that arrives continuously. I want to draw "Real-time" plot/graph using it. Is that possible?
I.E. I don't want just a static graph of a one-time read of a file - I want the streaming data plotted and continued out to the right of the graph - (and let the left side fall off/scroll out of view)
EDIT
I still have not gotten an answer for this. There is an interesting class in the wxmathPlot library called mpFXYVector but that appears just to draw one plot from a vector of data. What I want is something that can be fed a stream and scroll the graph horizontally (and also resize the scale if needed)
发布评论
评论(6)
谢谢乌鸦点...!! 我按照你说的做了..它工作完美!
这是我的 AddData() 函数:
在 Main() 中你只需要:
Thanks ravenspoint...!! I did what you said.. It works flawless!
here is my AddData() function:
in the Main() you only have to:
我认为 mpFXYVector 是正确的选择。
处理这个问题的最简单方法可能是为 mpFXYVector 编写一个包装类,它保存最近数据点的 FIFO 缓冲区。 每次新数据点到达时,将其添加到 FIFO 缓冲区,这将删除最旧的点,然后使用更新的缓冲区加载 mpFXYVector。 wxMathPlot 类 mpWindow 将处理您需要的其余部分。
更优雅的方法是 mpFXYVector 的专门化,它使用 mpFXYVector 中的简单向量来实现 FIFO 缓冲区。 这样做的优点是您只持有显示数据的一份副本。 除非您要显示数千个点,否则我怀疑从 mpFXYVector 继承的优势是否值得付出额外的麻烦,而不是简单地使用 mpFXYVector 记录的接口。
查看详细信息后,唯一棘手的一点是用新方法 Add() 替换 mpFXYVector::SetData(),以便在数据点到达时添加它们。 新方法需要将 mpFXYVector 向量作为 FIFO 缓冲区进行管理,并重新实现代码以更新边界框(不幸的是,编写时没有考虑到继承)。
结果是,与使用包装器相比,专业化提供的解决方案具有更小的内存需求和更大的灵活性。
I think mpFXYVector is the way to go.
The simplest way to deal with this might be to write a wrapper class for mpFXYVector which holds a FIFO buffer of recent data points. Each time a new datapoint arrives, add it to the FIFO buffer, which will drop the oldest point, then load mpFXYVector with the updated buffer. The wxMathPlot class mpWindow will look after the rest of what you need.
A more elegant approach would be a specialization of mpFXYVector which implements the FIFO buffer, using the simple vectors in mpFXYVector. The advantage of this would be that you are holding just one copy of the display data. Unless you are displaying many thousands of points, I doubt the advantage is worth the extra trouble of inheriting from mpFXYVector, rather than simply using the mpFXYVector documented interface.
After looking at the details, the only tricky bit is to replace mpFXYVector::SetData() with a new method Add() to add data points as they arrive. The new method needs to manage the mpFXYVector vectors as FIFO buffers, and to re-implement the code to update the bounding box ( which unfortunately was not written with inheritance in mind ).
The result is that specialization gives a solution with a smaller memory requirement and more flexibility than using a wrapper.
我知道这是一个旧线程,但我需要使用 wxMathPlot 绘制滚动 X 轴。
我对 jayjo 的代码做了一个简单的修改,以使 X 轴滚动工作。
我希望这有帮助。
I know this is an old thread but I needed to plot a scrolling X axis with wxMathPlot.
I've done a simple modification to jayjo's code to make X axis scrolling work.
I hoe this helps.
我对 wxMathPlot 没有任何个人经验,但我多年来一直在使用 wxWidgets,并强烈推荐它用于 C++ 中的跨平台 GUI 编程,根据 wxWiki 图形页面 Numerix 图形库可用于实时数据,因此也许可以帮助您。 祝你好运。
I do not have any personal experience with wxMathPlot, but I have been working with wxWidgets for years and highly recommend it for cross platform gui programming in c++, with that said according to the wxWiki graphics page the Numerix Graphics Library can be used for real time data so maybe that can help you out. Good luck.
也许有人会遇到同样的问题并且需要它......我需要非常快速的绘图来显示示波器的数据。
我正在以数据包的形式获取数据。 我做了一些更改,使代码快了很多。
首先是将函数
SetData
中的 if 状态从if (xs.size()>0)
更改为if (!xs.empty)
代码>.然后,您应该首先将所有数据包添加到向量中
,然后您应该拟合并设置数据。
主函数中的代码会更长,但函数会更快,因为您“一次”添加所有数据。
Maybe someone will have same problem and will need it... I needed very fast plotting for showing the data from oscilloscope.
I was getting the data in packets. I made few changes that made a code a lot of faster.
First thing is to change the if state in function
SetData
fromif (xs.size()>0)
toif (!xs.empty)
.Then you should firstly add all of your data packet to the vector
And after that you should fit and set data.
Your code in main function will be longer but function will be faster because you add all data "at once".
我们最终使用 ChartDirector 代替。 它具有很多功能并且速度很快。
We ended up using ChartDirector instead. It has a lot of capability and is fast.