下载与安装

要使用qcustomplot,首先需要在官网下载qcustomplot。
下载链接。
下载完成后,打开解压压缩包,添加qcustomplot.c和qcustomplot.h到目标工程文件。

打开工程文件中的examples中的实例。
可以看到有许多工程示例:
动态实时曲线绘制就需要用到setupRealtimeDataDemo这个demo:
源码如下:


void MainWindow::setupRealtimeDataDemo(QCustomPlot *customPlot)
{demoName = "Real Time Data Demo";// include this section to fully disable antialiasing for higher performance:/*customPlot->setNotAntialiasedElements(QCP::aeAll);QFont font;Afont.setStyleStrategy(QFont::NoAntialias);customPlot->xAxis->setTickLabelFont(font);customPlot->yAxis->setTickLabelFont(font);customPlot->legend->setFont(font);*/customPlot->addGraph(); // blue linecustomPlot->graph(0)->setPen(QPen(QColor(40, 110, 255)));customPlot->addGraph(); // red linecustomPlot->graph(1)->setPen(QPen(QColor(255, 110, 40)));customPlot->addGraph(); // red linecustomPlot->graph(2)->setPen(QPen(QColor(90, 140, 40)));QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);timeTicker->setTimeFormat("%h:%m:%s");customPlot->xAxis->setTicker(timeTicker);customPlot->axisRect()->setupFullAxesBox();customPlot->yAxis->setRange(0, 10);// make left and bottom axes transfer their ranges to right and top axes:connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));// setup a timer that repeatedly calls MainWindow::realtimeDataSlot:connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));dataTimer.start(10); // Interval 0 means to refresh as fast as possible
}

定时器溢出的槽函数:

void MainWindow::realtimeDataSlot()
{static QTime timeStart = QTime::currentTime();// calculate two new data points:double key = timeStart.msecsTo(QTime::currentTime())/1000.0; // time elapsed since start of demo, in secondsstatic double lastPointKey = 0;if (key-lastPointKey > 0.002) // at most add point every 2 ms{// add data to lines:ui->customPlot->graph(0)->addData(key, qSin(key)+std::rand()/(double)RAND_MAX*1*qSin(key/0.3843));ui->customPlot->graph(1)->addData(key, qCos(key)+std::rand()/(double)RAND_MAX*0.5*qSin(key/0.4364));// rescale value (vertical) axis to fit the current data://ui->customPlot->graph(0)->rescaleValueAxis();//ui->customPlot->graph(1)->rescaleValueAxis(true);lastPointKey = key;}// make key axis range scroll with the data (at a constant range size of 8):ui->customPlot->xAxis->setRange(key, 8, Qt::AlignRight);ui->customPlot->replot();// calculate frames per second:static double lastFpsKey;static int frameCount;++frameCount;if (key-lastFpsKey > 2) // average fps over 2 seconds{ui->statusBar->showMessage(QString("%1 FPS, Total Data points: %2").arg(frameCount/(key-lastFpsKey), 0, 'f', 0).arg(ui->customPlot->graph(0)->data()->size()+ui->customPlot->graph(1)->data()->size()), 0);lastFpsKey = key;frameCount = 0;}
}

实现效果:

QT绘制实时动态曲线——qcustomplot使用(一)相关推荐

  1. QT 绘制贝塞尔曲线,并且获得曲线上的点的坐标

    贝塞尔曲线的几个步骤 1.起始点 2.控制点 3.控制点 4.结束点 附上下图(网上找的) 利用QT绘制曲线然后通过定时器遍历整条曲线,先看一下效果: 实现代码: #pragma once #incl ...

  2. python实时绘制动态曲线_pyqt中使用matplotlib绘制动态曲线

    一.项目背景: 看了matplotlib for python developers这本书,基本掌握了在pyqt中显示曲线的做法,于是自己写一个. 二.需求描述: 1)X轴显示时间点,显示长度为1分钟 ...

  3. qt之QCustomPlot与qchart初级应用-----绘制动态曲线

    一.前言 早就想发这个帖子了,但由于单位项目比较紧,一直没腾出时间去学习和发博客,今天趁着再次接触了一下QCustomPlot,把上次要 发的qchart和QCustomPlot做的一些初级练习发出来 ...

  4. 【QCustomPlot】1.2 - QCustomPlot绘制静态曲线、常用函数的功能说明

    使用QCustomPlot绘制静态曲线.并对常用函数的功能进行说明. 大部分参照别人博客,以在代码工程中附上了链接. 我的学习例程仓库,GitHub:QCustomPlot 学习例程下载 绘图坐标轴布 ...

  5. Qt学习:QtCharts绘制动态曲线,实时更新数据与坐标轴

    前言:很久之前写了这篇文章后一直未进行修改更新,最近重新整理了代码和扩展了使用方式.代码路径见github: https://github.com/LYH-ux/Qt_Projects.git ,下文 ...

  6. MFC中绘制动态曲线

    在工控监测领域,经常需要动态绘制曲线,观察曲线的变化趋势,绘制波形图,绘制频谱等.在前面4讲中介绍了MFC经常用的TeeChart控件和Hight-Speed Chart Ctrl,这两个都是MFC绘 ...

  7. qlineseries绘制动态曲线_Qt绘制动态曲线

    首先*.pro文件中加一句 QT += charts 然后 mainwindow.cpp文件如下: #include "mainwindow.h" #include "u ...

  8. R语言构建logistic回归模型并评估模型:模型预测结果抽样、可视化模型分类预测的概率分布情况、使用WVPlots包绘制ROC曲线并计算AUC值

    R语言构建logistic回归模型并评估模型:模型预测结果抽样.可视化模型分类预测的概率分布情况.使用WVPlots包绘制ROC曲线并计算AUC值 目录

  9. R语言使用pROC包绘制ROC曲线、获取最优阈值(threshold)及最优阈值对应的置信区间

    R语言使用pROC包绘制ROC曲线并获取最佳阈值(threshold)及最佳阈值对应的置信区间 #ROC曲线 ROC(receiver operating characteristic curve)接 ...

  10. R语言使用pROC包绘制ROC曲线并使用smooth函数绘制平滑的ROC曲线(方法包括:binormal、density、fitdistr、logcondens、logcondens.smooth)

    R语言使用pROC包绘制ROC曲线并使用smooth函数绘制平滑的ROC曲线(方法包括:binormal.density.fitdistr.logcondens.logcondens.smooth) ...

最新文章

  1. SORT,DELETE ADJACEN DUPLICATES FROM保留有效数据
  2. 企业的核心竞争力是什么
  3. HDU - 4027 Can you answer these queries?(线段树)
  4. SAP Spartacus 重用组件cx-table的设计原理
  5. Win7 64有点找不到MSVCP71.DLL和MSVCR71.dll
  6. mysql -connector/j驱动下载
  7. 《Linux内核修炼之道》——2.2 编译内核
  8. GNN + Zero-shot
  9. Python编程笔记(第一篇)Python基础语法
  10. 【延展Extension的使用场景 Objective-C语言】
  11. 计算机开启telnet服务,Telnet服务是什么?如何开启Telnet服务
  12. 【前端】静态网页和动态网页
  13. MySQL学习笔记(二)
  14. 曙光服务器bios开启vt虚拟化,VT开启教程 BIOS开启VT方法
  15. HTML如何做一张李白的静夜思,李白《静夜思》配图赏析
  16. ansible中的加密
  17. 10天学会PHP之PHP快速入门
  18. 使用苹果cms建视频类的网站
  19. 深入浅出HTML(针对后端攻城狮)
  20. 小程序之上传多张图片

热门文章

  1. 上海房屋租赁合同登记备案证明办理流程
  2. Unity资源的基本类型
  3. java删除某些段落word_Java 批量删除Word中的空白段落
  4. 你不知道的“虚假需求”
  5. java quartz 每月1号执行_Quartz 每月1号 执行规则表达式
  6. JTT808、JTT809、JTT796、JTT794、JTT1077、JTT1078区别与交通部道路运输车辆卫星定位系统部标标准大全下载地址...
  7. 最大熵马尔可夫模型MEMM
  8. pipreqs 命令 ConnectionResetError(10054, ‘An existing connection was forcibly closed by the remote hos
  9. svn如何提取文件更新列表
  10. Hyper-V虚拟光纤通道