PDA

View Full Version : Extra line appears on plot with startTimer()



GG2013
26th July 2013, 02:23
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.

9366



Plot::Plot(QWidget *parent ): QwtPlot( parent )
{
….
…
(void) startTimer(1000);// 1 sec

//populate(); //this works fine

connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ),
SLOT( legendChecked( const QVariant &, bool ) ) );

}

void Plot::populate()
{
….Read data from a file…..

for ( int c = 0; c < 3; c++ )
data[c].curve->setRawSamples(&timeData.front(), &yData[c].front(), timeData.size() );

}

void Plot::timerEvent(QTimerEvent *)
{
populate(); //Getting data for plotting
replot(); // to refresh plot
}

Uwe
26th July 2013, 06:51
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

GG2013
29th July 2013, 00:28
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.