How can I make "real" charts using wxMathPlot?

I am thinking of using wxMathPlot to build / graphically display some data that comes in continuously. I want to draw a graph "Real-time graph / graph" using it. Is it possible?

those. I don’t need only a static graph of a one-time reading of a file - I want streaming data to be built and continued to the right of the graph - (and let the left side drop off / scroll from the view)

EDIT

I still have not received an answer. The wxmathPlot library has an interesting class called mpFXYVector, but it appears only to draw a single graph from a data vector. What I want is what can be filed by the stream and scroll the graph horizontally (and also, if necessary, change the scale size)

+4
source share
6 answers

I think mpFXYVector is the way to go.

The simplest way to handle this would be to write a wrapper class for mpFXYVector, which contains the FIFO buffer of the last data points. Each time a new datapoint arrives, add it to the FIFO buffer, which will display the oldest point, then load mpFXYVector with the updated buffer. The wxMathPlot mpWindow class will keep track of the rest of what you need.

A more elegant approach would be the specialization of mpFXYVector, which implements the FIFO buffer using simple vectors in mpFXYVector. The advantage of this is that you keep only one copy of the displayed data. If you don’t show many thousands of points, I doubt that the advantage is worth the extra problems with inheriting from mpFXYVector, and not just using the documented mpFXYVector interface.

After viewing the details, the only difficult bit is to replace mpFXYVector :: SetData () with the new Add () method to add data points as they arrive. The new method is to manage the mpFXYVector vectors as FIFO buffers and reimplement the code to update the bounding box (which, unfortunately, was not written with inheritance).

As a result, specialization provides a solution with less memory and more flexibility than using a wrapper.

+3
source

Thanks ravenspoint ... !! I did what you said. It works flawlessly! here is my AddData () function:

void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys) { // Check if the data vectora are of the same size if (xs.size() != ys.size()) { wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!")); return; } //Delete first point if you need a filo buffer (i dont need it) //xs.erase(xs.begin()); //xy.erase(xy.begin()); //Add new Data points at the end xs.push_back(x); ys.push_back(y); // Copy the data: m_xs = xs; m_ys = ys; // Update internal variables for the bounding box. if (xs.size()>0) { m_minX = xs[0]; m_maxX = xs[0]; m_minY = ys[0]; m_maxY = ys[0]; std::vector<double>::const_iterator it; for (it=xs.begin();it!=xs.end();it++) { if (*it<m_minX) m_minX=*it; if (*it>m_maxX) m_maxX=*it; } for (it=ys.begin();it!=ys.end();it++) { if (*it<m_minY) m_minY=*it; if (*it>m_maxY) m_maxY=*it; } m_minX-=0.5f; m_minY-=0.5f; m_maxX+=0.5f; m_maxY+=0.5f; } else { m_minX = -1; m_maxX = 1; m_minY = -1; m_maxY = 1; } } 

in Main () you only need:

 m_Vector->AddData(xPos,yPos,vectorX, vectorY); m_plot->Fit(); 
+4
source

I know this is an old thread, but I needed to build a rolling X axis using wxMathPlot.

I made a simple modification of the jayjo code to scroll along the X axis.

I will help him help.

 void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys) { // Check if the data vectora are of the same size if (xs.size() != ys.size()) { wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!")); return; } //After a certain number of points implement a FIFO buffer //As plotting too many points can cause missing data if (x > 300) { xs.erase(xs.begin()); ys.erase(ys.begin()); } //Add new Data points at the end xs.push_back(x); ys.push_back(y); // Copy the data: m_xs = xs; m_ys = ys; // Update internal variables for the bounding box. if (xs.size()>0) { m_minX = xs[0]; m_maxX = xs[0]; m_minY = ys[0]; m_maxY = ys[0]; std::vector<double>::const_iterator it; for (it=xs.begin();it!=xs.end();it++) { if (*it<m_minX) m_minX=*it; if (*it>m_maxX) m_maxX=*it; } for (it=ys.begin();it!=ys.end();it++) { if (*it<m_minY) m_minY=*it; if (*it>m_maxY) m_maxY=*it; } m_minX-=0.5f; m_minY-=0.5f; m_maxX+=0.5f; m_maxY+=0.5f; } else { m_minX = -1; m_maxX = 1; m_minY = -1; m_maxY = 1; } } 
+3
source

I have no personal experience with wxMathPlot, but I have been working with wxWidgets for many years and highly recommend it for cross-platform gui programming in C ++, moreover, it says according to the wxWiki graphic page. Numerix graph library can be used for real-time data , so maybe this can help you out. Good luck.

+2
source

Perhaps someone will have the same problem and need it ... I need a very fast plotting to display data from the oscilloscope. I received data in packets. I made a few changes that made the code a lot faster. First of all, you need to change the if state in the SetData function from if (xs.size()>0) to if (!xs.empty) . Then you must first add your entire data packet to the vector

 Vector1_X.push_back(x); Vector1_Y.push_back(y); 

And after that you have to install and install the data.

 Vector1 ->SetData(Vector1_X,Vector1_Y); // add vectors to main vector MathPlot1-> Fit(); //fit plot to the data Vector1_X.clear(); //if you want to clear plot after every packet Vector1_Y.clear(); //you should use it 

Your code in the main function will be longer, but the function will be faster, because you will add all the data “at once”.

+2
source

In the end, we used ChartDirector . It has many features and fast.

+1
source

Source: https://habr.com/ru/post/1286164/


All Articles