Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to get current updated time at each tickerlabel in x axis data plot
QtWS25 Last Chance

how to get current updated time at each tickerlabel in x axis data plot

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 308 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    subrat
    wrote on last edited by subrat
    #1

    here is my code,but i am getting updated time at all ticker
    please help

    void 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..

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved