QCustomPlot Discussion and Comments

realtime dataReturn to overview

I made the data change using a double spin box, but the graph changes without pressing push button, so I want to apply the data using push button, what should I do?


void MainWindow::realtimeDataSlot()
{
// calculate two new data points:
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
double key = 0;
#else
double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
#endif
static double lastPointKey = 0;
if (key-lastPointKey > 0.01) // at most add point every 10 ms
{
double value0 = ui->sp_1->value();
// add data to lines:
ui->customPlot->graph(0)->addData(key, value0);
// set data of dots:
ui->customPlot->graph(2)->clearData();
ui->customPlot->graph(2)->addData(key, value0);
ui->customPlot->graph(3)->clearData();
// remove data of lines that's outside visible range:
ui->customPlot->graph(0)->removeDataBefore(key-8);
ui->customPlot->graph(1)->removeDataBefore(key-8);
// 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+0.25, 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()->count()+ui->customPlot->graph(1)->data()->count())
, 0);
lastFpsKey = key;
frameCount = 0;
}
}

I used example number 10 of plot provided by custom plot.