下载与安装

要使用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. 什么是条件组合覆盖_物史政组合分析,新高考最终受益者丨选科17期
  2. 管理到底是“管人”还是“管事”,百分之九十的人理解有问题
  3. 计算机图形软件---图形功能
  4. Code First 数据库的表中属性的配置
  5. 助力健康中国,国内首个中文医疗信息处理挑战榜正式发布
  6. ubuntu 设置root启动
  7. 【图】一只Android开发程序猿对IMの所有痴情,你会懂?
  8. 初识神经网络NeuralNetworks
  9. oracle数据库怎么删除数据库,oracle数据库如何删除 oracle数据库删除方法
  10. html5日程管理系统,有条不紊:四款桌面日程管理软件横测
  11. python循环括号_Python3中小括号()、中括号[]、花括号{}的区别详解
  12. scala打印服务器消息,Spark中使用Scala实现WordCount业务
  13. (转)apple-touch-icon-precomposed 和 apple-touch-icon属性区别
  14. granfana 使用cdn模式加速页面加载
  15. FCM——(Fuzzy C-means)模糊C均值算法
  16. error: field ‘ifru_hwaddr’ has incomplete type
  17. CCF 202206-2 寻宝!大冒险!
  18. 6轮面试辛苦拿到阿里Android开发offer,却从22k降到15k,在逗我
  19. 在Win32中使用OpenGL
  20. 【光照感知子场:差分感知融合模块与中间融合策略相结合】

热门文章

  1. DCDC电源中同步与异步的区别
  2. 【python 作日期的折线图和柱状图组合图】
  3. echart柱状图和折线图混合
  4. VMware虚拟机win7安装教程
  5. latex学习记录1:图片文字排版
  6. 【第三方支付通道】第三方支付接口如何对接?
  7. 【高等数学】平面束方程的俩种设法与其中一种设法会出现的漏解问题
  8. Module ‘xxx‘ was created for incompatible target arm64-apple-ios9.0 Xcode12 错误解决
  9. 自己搭建微信小程序服务器,微信小程序搭建自己的Https服务器
  10. 计算机Wor表格制作斜线表头,Word文档里怎么画表格斜线表头