需要使用到第三方库,Qcustomplot,可以去官网下载源码.h和.cpp文件,然后当成普通文件导入自己的项目即可。
直接上代码。绘制了4个图,用定时器器不断更新图形,其实就是刷新坐标数据。
.h文件代码
#ifndef CUSTOMPLOT_H
#define CUSTOMPLOT_H
#include <QWidget>
#include "qcustomplot.h"
#include <QTimer>
#include <iostream>
QT_BEGIN_NAMESPACE
namespace Ui { class Customplot; }
QT_END_NAMESPACE
class Customplot : public QWidget
{
Q_OBJECT
public:
Customplot(QWidget *parent = nullptr);
~Customplot();
private:
void initData();
void initUi();
void initSlots();
private slots:
void changWave();
private:
Ui::Customplot *ui;
QVector<QCustomPlot *>cpt;
QVector<double> x; ///< x坐标数据
QVector<double> y; ///< y坐标数据
int num; ///&l