C ++ Qwt - building data from a vector

I am trying to build a graph based on the data that I received and stored inside a vector, but I can not find any tutorials or links there and give me any indications of what I need to do. So here is my code:

class Plotter : public QwtPlot { public: Plotter() { } }; int main( int argc, char **argv ) { QApplication app(argc, argv); //Plotter *d_plot = new Plotter(); Plotter* d_plot = new Plotter(); d_plot->setTitle("DEMO"); d_plot->setCanvasBackground(Qt::white); d_plot->setAxisScale( QwtPlot::yLeft, 0.1, 50.0 ); d_plot->setAxisScale(QwtPlot::yRight, 0.1, 50.00); // PLOT THE DATA std::vector<double> data; data.push_back(1.03); data.push_back(13.12); //.... d_plot->resize( 600, 400 ); d_plot->show(); return app.exec(); } 

Can someone give me any ideas on what function I could use to let me build the data?

thanks

+6
source share
2 answers

Check the QwtPlot docs: usually you create a QwtPlotCurve , use QwtPlotCurve::setSamples to get the data, and then QwtPlotCurve::attach to get the data.

There should be something like this:

 std::vector<double> x; std::vector<double> y; //fill x and y vectors //make sure they're the same size etc QwtPlotCurve curve( "Foo" ); //or use &x[ 0 ] or &(*x.first()) pre-C++11 cure.setSamples( x.data(), y.data(), (int) x.size() ); curve.attach( &plot ); 

http://qwt.sourceforge.net/class_qwt_plot_curve.html

http://qwt.sourceforge.net/class_qwt_plot.html

+6
source

One way is to snap a curve to your plot, i.e.:

 QwtPlotCurve myCurve; myCurve->attach(&d_plot); 

Then you can use (in a member function or anywhere) the QwtPlotCurve::setRawSample , which has the following pretty clear signature:

 void QwtPlotCurve::setRawSample(const double* xData, const double* yData, int size); 

Define your data and then call replot() to update the schedule. This means that you must also have a vector for x values.

The code will look like this:

 int main( int argc, char **argv ) { //... Plotter* d_plot = new Plotter(); //Plot config // PLOT THE DATA std::vector<double> data_y; data_y.push_back(1.03); data_y.push_back(13.12); std::vector<double> data_x; data_x.push_back(1.0); data_x.push_back(2.0); //.... myCurve->setRawSample(data_x.data(),data_y.data(),data_y.size()); d_plot->resize( 600, 400 ); d_plot->replot(); d_plot->show(); //... } 

I suggest you study the Qwt doc about the curve

+4
source

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


All Articles