1 Attachment(s)
Weird 2nd line while plotting a real time curve consisting of negative axis
Hi all,
I'm a newbie in QWT. I'm trying to plot a real time curve that runs from -6 to 6. I'm able to get the real time plot to work with the help of Timer(). But there is a strange line extending to my plot when the graph plot itself(see attached photo). Any kind soul can tell me where am i getting it wrong?
My code are as follows:
void TimeLinearity1::populate1(int _time, QString wave1, QString wave2)
{
time = _time;
w1 = wave1;
w2 = wave2;
x1.resize(360),y1.resize(360);
if(w1 == "Square Wave")
{
for (int i=0; i<time; ++i)
{
x1[i] = (i/360.0-0.5)*30+0.01;
x1[i] *= 0.4;
if( x1[i]>=-2.5 && x1[i]<=2.5)
{
y1[i]=3;
}
else
{
y1[i]=0;
}
}
}
else if(w1 == "Triangle Wave")
{
for (int i=0; i<time; ++i)
{
x1[i] = (i/360.0-0.5)*30+0.01;
x1[i] *= 0.4;
if( x1[i]>=-2 && x1[i]<0)
{
y1[i]=(0.5*x1[i])+1;
}
else if(x1[i]>=0 && x1[i]<2)
{
y1[i]=1-(0.5*x1[i]);
}
else
{
y1[i]=0;
}
}
}
Wave->setPen( QColor(Qt::green) );
Wave->setSamples(x1, y1);
Wave->attach( this );
replot();
}
Thank you very much.
Attachment 11449
Re: Weird 2nd line while plotting a real time curve consisting of negative axis
Quote:
x1.resize(360),y1.resize(360);
With this line you create two vectors, initialized with (0,0) points. Then your loop doesn't replace all of them - that's why you see the lines to (0, 0 ).
Try "qDebug() << x1;" and you will see it.
HTH,
Uwe
Re: Weird 2nd line while plotting a real time curve consisting of negative axis
Thanks Uwe, yeap I saw the message from qdebug. the initial values is all 0.
I tried not declaring it size first and uses "x1.push_back(x);" But im still facing trouble. Is there a way to actually go around this problem?
Really sorry to trouble you.
Regrads,
Tong14