Results 1 to 3 of 3

Thread: Weird 2nd line while plotting a real time curve consisting of negative axis

  1. #1
    Join Date
    Sep 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default 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:opulate1(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.

    plot.jpg

  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: Weird 2nd line while plotting a real time curve consisting of negative axis

    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

  3. #3
    Join Date
    Sep 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default 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

Similar Threads

  1. Replies: 3
    Last Post: 28th June 2013, 16:04
  2. Real time plotting from hardware
    By astodolski in forum Qwt
    Replies: 5
    Last Post: 15th April 2013, 13:14
  3. Qwt real time plotting
    By santoshpradeep in forum Qwt
    Replies: 8
    Last Post: 28th June 2012, 09:53
  4. real time plotting
    By agostain in forum Qwt
    Replies: 0
    Last Post: 10th August 2009, 10:47
  5. real time plotting
    By gyre in forum Qwt
    Replies: 4
    Last Post: 11th December 2007, 16:13

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.