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))); QSharedPointerQCPAxisTickerTime 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 DemoQCPAxisTicker Class Reference
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2521286.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!