Results 1 to 3 of 3

Thread: How to real time plot?

  1. #1
    Join Date
    Aug 2014
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question How to real time plot?

    I'm want to draw a sinusoid that is updated every 100ms after a button is clicked. What I'm doing is, when the button is clicked, 2000 points are plotted with x and y values equal 0 and then, the timer is started. Every tick of the clock updates the plot, "moving" all the values to the left (what will remove the first value of the series) and adding a new valeu to the end.

    I make this but the plot just don't update. I'm sure the problem isn't with the Timer.

    PS: sorry for my English.

    Global variables:
    Qt Code:
    1. double i;
    2. QwtPlotCurve *curve;
    3. QPolygonF points;
    4. QPointF point;
    To copy to clipboard, switch view to plain text mode 

    Event button clicked:

    Qt Code:
    1. void MainWindow::on_btnDraw_clicked()
    2. {
    3. i=0;
    4.  
    5. ui->qwtPlot->setTitle("Test Plot");
    6. ui->qwtPlot->setCanvasBackground(Qt::white);
    7. ui->qwtPlot->setAxisScale(QwtPlot::yLeft, -2.0, 2.0);
    8. ui->qwtPlot->setAxisScale(QwtPlot::xBottom, 0.0, 20.0);
    9. ui->qwtPlot->updateAxes();
    10.  
    11. curve = new QwtPlotCurve("Points");
    12. curve->setPen(Qt::blue,1);
    13. curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
    14.  
    15. grid = new QwtPlotGrid();
    16. grid->show();
    17. grid->attach(ui->qwtPlot);
    18.  
    19. for(i=0;i<2000;i++)
    20. {
    21. point.setX(0);
    22. point.setY(0);
    23. points += point;
    24. }
    25.  
    26. curve->setSamples(points);
    27. curve->attach(ui->qwtPlot);
    28.  
    29. ui->qwtPlot->update();
    30.  
    31. timer = new QTimer(this);
    32. timer->setInterval(100);
    33. timer->start();
    34. connect(timer,SIGNAL(timeout()),this,SLOT(Update()));
    35. }
    To copy to clipboard, switch view to plain text mode 

    Update() function:

    Qt Code:
    1. void MainWindow::Update()
    2. {
    3. ui->qwtPlot->setAxisAutoScale(QwtPlot::yLeft, true);
    4. ui->qwtPlot->setAxisAutoScale(QwtPlot::xBottom, true);
    5. ui->qwtPlot->updateAxes();
    6.  
    7. for(int j=0;j<points.count()-1;j++)
    8. {
    9. points.value(i)=points.value(i+1);
    10. }
    11.  
    12. i+=0.1;
    13. point.setX(i);
    14. point.setY(sin(i));
    15. points += point;
    16.  
    17. curve->setSamples(points);
    18. curve->attach(ui->qwtPlot);
    19.  
    20. ui->qwtPlot->update();
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by RafaelRSE; 6th August 2014 at 15:21.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to real time plot?

    See QwtPlot::replot()

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    RafaelRSE (7th August 2014)

  4. #3
    Join Date
    Aug 2014
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to real time plot?

    Thanks, I found the solution. I just needed to add the line:

    Qt Code:
    1. ui->qwtPlot->setAutoReplot(true);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Plot the graph for real time data
    By swinetha in forum Qwt
    Replies: 13
    Last Post: 1st August 2013, 04:56
  2. Replies: 3
    Last Post: 12th April 2013, 06:18
  3. How to plot real time x/y graph in Qtopia
    By desperado_43 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 18th May 2012, 08:00
  4. real time graph plot
    By robotics in forum Qt Programming
    Replies: 5
    Last Post: 24th May 2011, 05:04
  5. QFileSystemWatcher with a Qwt Real-time plot
    By gen_mass in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2010, 21:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.