Слияние кода завершено, страница обновится автоматически
#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;
}
}
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )