Results 1 to 3 of 3

Thread: Continuous x-axis qwt realtime plot

  1. #1
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Continuous x-axis qwt realtime plot

    I am trying to make a realtime plot and so far I got it to show a continuous sine wave, but the plot is not moving continuously on the x-axis, but more like every second it jumps one tick to the left. How can I fix this when using the QwtDateScaleDraw and QwtDateScaleEngine? I am sure it is easy, but I can not figure it out...

    My code:

    Qt Code:
    1. MyPlot::MyPlot(QWidget *parent) : QWidget(parent)
    2. {
    3. xData = new QList<double>();
    4. yData = new QList<double>();
    5. plot = new QwtPlot(this);
    6. layout = new QHBoxLayout();
    7.  
    8. //Add widget to layout.
    9. layout->addWidget(plot);
    10.  
    11. //Add curves.
    12. curve1 = new QwtPlotCurve("Curve 1");
    13. curve1->setSamples(xData->toVector(), yData->toVector());
    14. curve1->attach(plot);
    15.  
    16. //Set x-axis scaling.
    17. QwtDateScaleDraw *qwtDateScaleDraw = new QwtDateScaleDraw (Qt::OffsetFromUTC);
    18. QwtDateScaleEngine *qwtDateScaleEngine = new QwtDateScaleEngine(Qt::OffsetFromUTC);
    19. qwtDateScaleDraw->setDateFormat(QwtDate::Second, "hh:mm:ss");
    20. qwtDateScaleDraw->setUtcOffset(QDateTime::currentMSecsSinceEpoch() / 1000);
    21.  
    22. plot->setAxisScaleDraw ( QwtPlot::xBottom, qwtDateScaleDraw);
    23. plot->setAxisScaleEngine ( QwtPlot::xBottom, qwtDateScaleEngine);
    24. plot->setAxisMaxMajor(QwtPlot::xBottom, 0);
    25. plot->setAxisMaxMinor(QwtPlot::xBottom, 10);
    26.  
    27. //Replot.
    28. plot->replot();
    29.  
    30. //Simulated data timer.
    31. QTimer *timer = new QTimer(this);
    32. connect(timer, SIGNAL(timeout()), this, SLOT(appendData()));
    33. timer->start(1);
    34. }
    35.  
    36. void MyPlot::appendData()
    37. {
    38. static unsigned int counter = 0;
    39.  
    40. //Add new data.
    41. xData->append(counter);
    42. yData->append(sin(M_PI*( (double)counter++ / 180)));
    43.  
    44. //Remove oldest data.
    45. if (yData->size() > 1000)
    46. {
    47. xData->removeFirst();
    48. yData->removeFirst();
    49. }
    50.  
    51. //Set data.
    52. curve1->setSamples(xData->toVector(), yData->toVector());
    53.  
    54. //Replot.
    55. plot->replot();
    56. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Continuous x-axis qwt realtime plot

    Use QwtPlot::setAxisScale for the X axis instead of using the autoscaler.

    Uwe

  3. #3
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: Continuous x-axis qwt realtime plot

    You are right! Thank you very much I did try it, but I obviously did something wrong. I still have a somewhat related problem with the timestamp label "hh:mm:ss" adjusting the x-axis every time a new x-axis label appears from the right. I guess the spacing between the major ticks changes and this looks like the x-axis is lagging a little. I would rather that the label is gradually becoming visible as the time (x-axis) increases in value. Like it fades in from the right y-axis border. Any quick tip? I have been looking at margins in the QwtDateScaleDraw and QwtDateScaleEngine, but no luck so far.
    Last edited by Phataas; 4th February 2015 at 23:10.

Similar Threads

  1. qwt realtime plot style
    By vanduongbk in forum Qwt
    Replies: 1
    Last Post: 16th May 2014, 09:16
  2. QWT realtime plot with scroll bar
    By CodingQt in forum Qwt
    Replies: 2
    Last Post: 6th November 2013, 18:38
  3. Replies: 0
    Last Post: 13th February 2013, 16:25
  4. Replies: 9
    Last Post: 3rd May 2011, 22:21
  5. QWT Realtime Plot zoom
    By Gavin Harper in forum Qwt
    Replies: 2
    Last Post: 13th September 2010, 09:04

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.