当前位置: 首页 > news >正文

Plot_setupRealtimeDataDemo

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; font.setStyleStrategy(QFont::NoAntialias); customPlot->xAxis->setTickLabelFont(font); customPlot->yAxis->setTickLabelFont(font); customPlot->legend->setFont(font); */ customPlot->addGraph(); // blue line customPlot->graph(0)->setPen(QPen(QColor(40, 110, 255))); customPlot->addGraph(); // red line customPlot->graph(1)->setPen(QPen(QColor(255, 110, 40))); QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime); // 时间刻度 timeTicker->setTimeFormat("%h:%m:%s"); customPlot->xAxis->setTicker(timeTicker); customPlot->axisRect()->setupFullAxesBox(); customPlot->yAxis->setRange(-1.2, 1.2); // 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))); QTimer dataTimer; // setup a timer that repeatedly calls MainWindow::realtimeDataSlot: connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot())); // F2快捷键 跳转定义 // 全速、实时、连续刷新画面 dataTimer.start(0); // 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 seconds 毫秒 - 秒 static 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(); // rescaleValueAxis(bool onlyVisible = false); true根据所有显示曲线调整范围 // 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 变量未初始化 默认值为0 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; } }
Real Time Data Demo
QCPAxisTicker Class Reference
http://www.jsqmd.com/news/646933/

相关文章:

  • 告别WAV文件:用Python客户端实时调用FunASR服务,实现流式语音识别与热词增强
  • WinUtil:如何快速配置Windows系统的完整工具集指南
  • # 008、模型评估:mAP、混淆矩阵——别让模型在测试集上“作弊”
  • 如何快速解密SWF文件:JPEXS逆向工具的完整指南
  • 联盟链核心协议体系详解:从章程到技术服务的完整框架
  • AI伦理自学路径:免费资源大全
  • 高企申报踩坑无数,广东这家15年本土机构 - 沐霖信息科技
  • 2025届毕业生推荐的十大降AI率助手解析与推荐
  • 别再死记硬背了!用Multisim仿真带你搞懂电容三端LC振荡器(考毕兹/克拉泼/西勒电路对比)
  • 企业知识竞赛系统选型指南:赋能培训与文化建设
  • 大麦网抢票终极指南:3步实现自动化购票系统
  • ComfyUI IPAdapter Plus插件:3分钟掌握图像风格迁移终极技巧
  • PX4飞控固件编译调试避坑实录:从GCC版本冲突到Python模块缺失的完整解决流程
  • 代码无界:多语言DApp交易所如何重构全球数字资产流动版图
  • 栈与队列---大学数据结构 #报告模板#集美大学#基础版#招学习搭子 私聊#PTA
  • 如何永久备份微信聊天记录:WeChatExporter完整教程
  • 基于模糊势场的多智能体协同编队控制仿真研究附Matlab代码
  • 3大核心功能+4种性能模式:华硕笔记本终极轻量控制方案G-Helper深度解析
  • 别再只盯着Transformer了!用MOE(专家混合)搞定亿级参数时序预测,附Time-300B数据集使用指南
  • CVPR 2024 热门数据集解析与应用指南
  • MRI脉冲序列设计的基石:手把手拆解布洛赫方程中的旋转矩阵(附Python模拟代码)
  • 如何在3分钟内为Windows 11 24H2 LTSC系统一键安装微软商店:完整免费解决方案指南
  • 从Maya到Unity的完整管线:角色模型导入+骨骼动画配置全流程实操
  • 多模态大模型能效比(Tokens/Watt)提升2.8倍的工业级实践(覆盖ViT+LLM联合剪枝、模态门控蒸馏、内存带宽自适应预取)
  • 3分钟学会AI音频修复:让模糊录音重获清晰生命的完整指南
  • 多模态大模型如何边学边用不遗忘?——揭秘动态参数隔离+梯度正交约束的双重增量稳态机制
  • 你的 Vue 3 defineProps(),VuReact 会编译成什么样的 React?
  • 基于CCA和VTP实现路径跟踪控制胡萝卜追逐算法和虚拟目标点附Matlab代码
  • 牛客:aoe还是单体
  • Gradle仓库配置优化:用阿里云镜像替代mavenCentral()、jcenter()和google()