how to get current updated time at each tickerlabel in x axis data plot
Unsolved
General and Desktop
-
here is my code,but i am getting updated time at all ticker
please helpvoid MainWindow::init_plot()
{
ui->plot->xAxis->setLabel("t [hh:mm:ss]");
ui->plot->yAxis->setLabel("V [mV]");ui->plot->addGraph(); // blue line ui->plot->graph(0)->setPen(QPen(Qt::blue)); ui->plot->addGraph(); // red line ui->plot->graph(1)->setPen(QPen(Qt::red)); ui->plot->addGraph(); // green line ui->plot->graph(2)->setPen(QPen(Qt::green)); ui->plot->axisRect()->setupFullAxesBox(); ui->plot->yAxis->setRange(0, 100); // make left and bottom axes transfer their ranges to right and top axes: connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->xAxis2, SLOT(setRange(QCPRange))); connect(ui->plot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->yAxis2, SLOT(setRange(QCPRange))); // setup a timer that repeatedly calls MainWindow::realtimeDataSlot: connect(&dateTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot())); dateTimer.start(0);
}
void MainWindow::realtimeDataSlot()
{QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime); QTime ti = QTime::currentTime(); QString tim = ti.toString("hh:mm:ss"); timeTicker->setTimeFormat(tim); ui->plot->xAxis->setTicker(timeTicker); static QTime time=QTime::currentTime(); ui->spinBox_2->setValue(ui->spinBox->text().toInt()+10); ui->spinBox_3->setValue(ui->spinBox->text().toInt()-20); // calculate two new data points: double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds static double lastPointKey = 0; if (key-lastPointKey > 0.002) // at most add point every 1s { // add data to lines: ui->plot->graph(0)->addData(key, ui->spinBox->text().toInt()); ui->plot->graph(1)->addData(key, ui->spinBox->text().toInt()+10); ui->plot->graph(2)->addData(key, ui->spinBox->text().toInt()-20); lastPointKey = key; } // make key axis range scroll with the data (at a constant range size of 8): if(ui->pushButton->text()=="stop") { ui->plot->xAxis->setRange(key, 8, Qt::AlignRight); ui->plot->replot(); }
}
please anyone give the solution..