C++ Qwt - 从 vector 中绘制数据

标签 c++ qt qwt

我正在尝试根据已获得并存储在 vector 中的数据绘制图表,但是,我似乎无法找到任何教程或引用资料,也无法指示我需要做什么。所以这是我的代码:

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();
}

谁能告诉我可以使用什么函数来绘制数据?

谢谢

最佳答案

检查 QwtPlot 文档:通常您创建一个 QwtPlotCurve,使用 QwtPlotCurve::setSamples 获取其中的数据,然后 QwtPlotCurve::attach 获取绘制的数据。

应该是这样的:

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

关于C++ Qwt - 从 vector 中绘制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18640701/

相关文章:

c++ - 是否可以为 constexpr 函数定义类型别名

c++ - Qt 5 是否支持异常?

mysql - Qt/线程事件循环 QTimer/MySQL 查询

javascript - 如何与来自 Node.js 进程的 C++ 程序输入流进行交互?

c++ - 想看懂这篇使用模板的论文

c++ - 为什么这些基于范围的 for 循环不能正常工作?

qt - 计算QPainterPath的填充区域

c++ - 使用 C++ 和 QWT 移动图形

c++ - qt creator 看不到 qwt header

qt - 与 Qwt 相比,QCustomPlot 的优点/缺点是什么?