代码拉取完成,页面将自动刷新
同步操作将从 风木/MyYoudaoNoteLike 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "myrealtimeplot.h"
#include <QDebug>
MyRealTimePlot::MyRealTimePlot(QCustomPlot *parent) :
QCustomPlot(parent)
{
QCustomPlot*customPlot=this;
customPlot->addGraph(); // blue line
customPlot->graph(0)->setPen(QPen(Qt::blue));
customPlot->graph(0)->setBrush(QBrush(QColor(240, 255, 200,180)));
customPlot->graph(0)->setAntialiasedFill(false);
customPlot->graph(0)->setChannelFillGraph(0);
customPlot->addGraph(); // red line
customPlot->graph(1)->setPen(QPen(Qt::red));
customPlot->graph(1)->setBrush(QBrush(QColor(204, 232, 207,180)));
customPlot->graph(1)->setChannelFillGraph(0);
customPlot->addGraph(); // blue dot
customPlot->graph(2)->setPen(QPen(Qt::blue));
customPlot->graph(2)->setLineStyle(QCPGraph::lsNone);
customPlot->graph(2)->setScatterStyle(QCPScatterStyle::ssDisc);
customPlot->addGraph(); // red dot
customPlot->graph(3)->setPen(QPen(Qt::red));
customPlot->graph(3)->setLineStyle(QCPGraph::lsNone);
customPlot->graph(3)->setScatterStyle(QCPScatterStyle::ssDisc);
customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
customPlot->xAxis->setAutoTickStep(false);
customPlot->xAxis->setTickStep(2);
customPlot->axisRect()->setupFullAxesBox();
// 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(0); // Interval 0 means to refresh as fast as possible
}
void MyRealTimePlot::realtimeDataSlot()
{
QCustomPlot*customPlot=this;
// calculate two new data points:
double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
static double lastPointKey = 0;
if (key-lastPointKey > 0.01) // at most add point every 10 ms
{
double value0 = qSin(key); //qSin(key*1.6+qCos(key*1.7)*2)*10 + qSin(key*1.2+0.56)*20 + 26;
double value1 = qCos(key); //qSin(key*1.3+qCos(key*1.2)*1.2)*7 + qSin(key*0.9+0.26)*24 + 26;
// add data to lines:
customPlot->graph(0)->addData(key, value0);
customPlot->graph(1)->addData(key, value1);
// set data of dots:
customPlot->graph(2)->clearData();
customPlot->graph(2)->addData(key, value0);
customPlot->graph(3)->clearData();
customPlot->graph(3)->addData(key, value1);
// remove data of lines that's outside visible range:
customPlot->graph(0)->removeDataBefore(key-8);
customPlot->graph(1)->removeDataBefore(key-8);
// rescale value (vertical) axis to fit the current data:
customPlot->graph(0)->rescaleValueAxis();
customPlot->graph(1)->rescaleValueAxis(true);
lastPointKey = key;
}
// make key axis range scroll with the data (at a constant range size of 8):
customPlot->xAxis->setRange(key+0.25, 8, Qt::AlignRight);
customPlot->replot();
// calculate frames per second:
static double lastFpsKey;
static int frameCount;
++frameCount;
if (key-lastFpsKey > 2) // average fps over 2 seconds
{
QString fps= QString("%1 FPS, Total Data points: %2")
.arg(frameCount/(key-lastFpsKey), 0, 'f', 0)
.arg(customPlot->graph(0)->data()->count()+customPlot->graph(1)->data()->count());
qDebug()<<fps;
lastFpsKey = key;
frameCount = 0;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。