QT使用qcustomplot绘图--查找数据库历史记录绘制

使用sqlite3数据库存储历史记录,点击查询历史曲线可以查看数据库中存储的历史记录并使用qcustomplot绘制成曲线,此处数据库中存储了多种型号多种参数。

1、使用sqlite3查询历史记录。

查找表中最后一百条数据命令:

QString cmd = QString("select * from %1 order by pk desc limit 100").arg(table_name);

2、给每条曲线中添加对应的数据。

while(query.next())
    {
        ui->curve1->graph(0)->addData(x_data,query.value(node_o2).toDouble());
        ui->curve1->graph(1)->addData(x_data,query.value(node_CO).toDouble());
        ui->curve1->graph(2)->addData(x_data,query.value(node_CO2).toDouble());
        ui->curve1->graph(3)->addData(x_data,query.value(node_CH4).toDouble());
        ui->curve1->graph(4)->addData(x_data,query.value(node_Humidity).toDouble());
        ui->curve1->graph(5)->addData(x_data,query.value(node_temp).toDouble());
        x_data++;
    }
ui->curve1->replot();
时间可能不连续,所以X轴直接使用0-100代替。

3、显示结果。

 


 

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Link-Riley曲线是一种常用于滤波器设计中的图形,可以使用QCustomPlot库在QT绘制。以下是绘制Link-Riley曲线的步骤: 1. 在QT中创建一个QWidget或QMainWindow窗口,并在该窗口中添加QCustomPlot小部件。 2. 将以下代码添加到QWidget或QMainWindow的槽函数中,以绘制Link-Riley曲线: ``` QCustomPlot *customPlot = ui->customPlot; // 获取QCustomPlot小部件的指针 customPlot->addGraph(); // 添加一个图形 customPlot->graph(0)->setPen(QPen(Qt::blue)); // 设置曲线的颜色 customPlot->graph(0)->setName("Link-Riley Curve"); // 设置曲线的名称 QVector<double> x(101), y(101); // 设置x和y向量 for (int i=0; i<101; i++) { double f = i/50.0; // 设置频率 double w = 2*M_PI*f; // 计算角频率 double a = 1/(1 + 0.414*pow(w, -1.0/2) + 0.707*pow(w, -1.0)); // 计算幅度响应 double phi = -atan(0.414*pow(w, -1.0/2) + 0.707*pow(w, -1.0)); // 计算相位响应 x[i] = f; // 设置x值 y[i] = 20*log10(a); // 计算dB值 } customPlot->graph(0)->setData(x, y); // 设置曲线的数据 customPlot->xAxis->setLabel("Frequency (Hz)"); // 设置x轴标签 customPlot->yAxis->setLabel("Magnitude (dB)"); // 设置y轴标签 customPlot->rescaleAxes(); // 自动缩放坐标轴 customPlot->replot(); // 绘制曲线 ``` 这段代码将在QCustomPlot小部件中添加一个蓝色的Link-Riley曲线。在这里,我们使用了Link-Riley滤波器的幅度响应和相位响应计算公式来计算曲线的值。在这里,我们使用了dB值来表示曲线的幅度。 3. 运行QT程序,即可看到绘制的Link-Riley曲线。可以使用QCustomPlot库的其他函数来更改曲线的样式、添加标签、设置坐标轴等。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值