Results 1 to 3 of 3

Thread: Extra line appears on plot with startTimer()

  1. #1
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Extra line appears on plot with startTimer()

    Hallo,
    I would like to read & plot data, say every 1 sec (i.e new curve should replace the old one). I have plotted the graph (see attached figure) okay but when I use the timer an extra line (average?) appears on graph. At the moment it's reading the same data every 1 sec but later it will be replaced by new set of data.

    Any idea why the extra line appears, and how to remove it?
    Thank you.

    Screenshot.jpg

    Qt Code:
    1. Plot::Plot(QWidget *parent ): QwtPlot( parent )
    2. {
    3. ….
    4. …
    5. (void) startTimer(1000);// 1 sec
    6.  
    7. //populate(); //this works fine
    8.  
    9. connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ),
    10. SLOT( legendChecked( const QVariant &, bool ) ) );
    11.  
    12. }
    13.  
    14. void Plot::populate()
    15. {
    16. ….Read data from a file…..
    17.  
    18. for ( int c = 0; c < 3; c++ )
    19. data[c].curve->setRawSamples(&timeData.front(), &yData[c].front(), timeData.size() );
    20.  
    21. }
    22.  
    23. void Plot::timerEvent(QTimerEvent *)
    24. {
    25. populate(); //Getting data for plotting
    26. replot(); // to refresh plot
    27. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Extra line appears on plot with startTimer()

    Because there is a wrong data point(s) at the end of your data - or the size is wrong and the last point is random ( often 0, 0 ).

    Uwe

  3. #3
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Extra line appears on plot with startTimer()

    Quote Originally Posted by Uwe View Post
    Because there is a wrong data point(s) at the end of your data - or the size is wrong and the last point is random ( often 0, 0 ).

    Uwe
    Thanks a lot Uwe. You are right. The vector size was growing each time the data file is read. Once I clear the vectors the trace is gone.

Similar Threads

  1. Replies: 1
    Last Post: 17th April 2012, 10:10
  2. Replies: 4
    Last Post: 11th May 2011, 19:15
  3. Replies: 10
    Last Post: 1st November 2010, 00:24
  4. Replies: 1
    Last Post: 19th September 2010, 20:50
  5. QTimer QBasicTimer and QObject::startTimer
    By SABROG in forum Qt Programming
    Replies: 7
    Last Post: 15th June 2009, 17:37

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.