Results 1 to 13 of 13

Thread: How to retain previous values in graph? QWT

  1. #1
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default How to retain previous values in graph? QWT

    Hello everyone!

    I am new to qwt and I am facing a problem that when I refresh my graph after 10 seconds my old graph is removed and new is plotted. What I want though is that my previous graph is retained and new values get plotted into the existing plot. Is there a way to do this?

    Here is my code (its just start code I have to so improvements in it also the data is large i can not plot it again from the start)

    Kindly help me, here is the code :

    double xs[100];
    double yT[100];
    double yP[100];
    static int j=0;
    myplot::myplot()
    {
    // add curves
    QwtPlotCurve *curveT = new QwtPlotCurve("Temperature");
    curveT->setPen(QPen(Qt::red,1));
    QwtPlotCurve *curveP = new QwtPlotCurve("Pressure");
    curveP->setPen(QPen(Qt::green,1));
    for (int i = 0; i < 100; i ++)
    {
    xs[i] = j;
    yT[i] = j;
    yP[i] = j+10;
    j++;
    }

    curveT->setRawSamples(xs,yT,100);

    curveP->setRawSamples(xs,yP,100);
    curveT->attach(this);
    curveP->attach(this);
    (void)startTimer(1000);

    }
    void myplot::newValues()
    {
    for (int i = 0; i < 100; i ++)
    {
    xs[i] = j+20;
    yT[i] = j+20;
    yP[i] = j+30;
    j++;
    }


    }
    void myplot::timerEvent(QTimerEvent * )
    {
    newValues();
    replot();
    }

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to retain previous values in graph? QWT

    Quote Originally Posted by maarvi View Post
    What I want though is that my previous graph is retained and new values get plotted into the existing plot. Is there a way to do this?
    So, you want to create two new curves (one for temperature and one for pressure) each time "newValues()" is called?

    Then you should not overwrite the old values. Create new curves and attach them to your plot.

    edit: please, use CODE-tags when you post source code...

  3. #3
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: How to retain previous values in graph? QWT

    ok sir thanks for your kind reply

    but the data is increasing continuously like 24 hr will it be ok?also sir kindly quide me a little more as i am first time using QWT

  4. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to retain previous values in graph? QWT

    Quote Originally Posted by maarvi View Post
    but the data is increasing continuously like 24 hr will it be ok?
    I don't know if that will be ok. but, when you add two curves each second, I strongly assume that the plot will look very confusing with thousands of curves....

  5. #5
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: How to retain previous values in graph? QWT

    sir i have made following changes but it didnt work

    double xs[10];
    double yT[10];
    double yP[10];
    static int j=0;
    myplot::myplot()
    {
    setTitle("A Simple QwtPlot Demonstration");
    // insertLegend(new QwtLegend(), QwtPlot::RightLegend);
    // Set axes
    // QwtInterval d_interval;
    setAxisTitle(xBottom, "time (sec)");
    setAxisScale(QwtPlot::xBottom,0,600,30);
    // setIntervalLength(20);

    setAxisTitle(yLeft, "Payload");
    setAxisScale(yLeft, 0,1000 ,10.0);

    // add curves
    QwtPlotCurve *curveT = new QwtPlotCurve("Temperature");
    curveT->setPen(QPen(Qt::red,1));
    QwtPlotCurve *curveP = new QwtPlotCurve("Pressure");
    curveP->setPen(QPen(Qt::green,1));
    for (int i = 0; i < 10; i ++)
    {
    xs[i] = j;
    yT[i] = j;
    yP[i] = j+10;
    j++;
    }

    curveT->setRawSamples(xs,yT,10);

    curveP->setRawSamples(xs,yP,10);
    curveT->attach(this);
    curveP->attach(this);
    (void)startTimer(1000);

    }
    void myplot::newValues()
    {

    QwtPlotCurve *curveT = new QwtPlotCurve("Temperature");
    curveT->setPen(QPen(Qt::red,1));
    QwtPlotCurve *curveP = new QwtPlotCurve("Pressure");
    curveP->setPen(QPen(Qt::green,1));


    for (int i = 0; i < 10; i ++)
    {
    xs[i] = j+20;
    yT[i] = j+20;
    yP[i] = j+30;
    j++;
    }

    curveT->setRawSamples(xs,yT,10);

    curveP->setRawSamples(xs,yP,10);
    curveT->attach(this);
    curveP->attach(this);

    }
    void myplot::timerEvent(QTimerEvent * )
    {


    newValues();
    replot();
    }

  6. #6
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to retain previous values in graph? QWT

    use "setSamples()" instead of "setRawSamples()". "setSamples()" copies the data while "setRawSamples()" only uses a reference.

    I assume, you are using Qwt 6, in the documentation of QwtPlotCurve I don't find a method "setRawSamples()". Uwe probably changed the name from "setRawData()". What I want to say, maybe you don't have a method "setSamples()". Try "setData()" then.

    and please, use code tags when you post source code...

  7. #7
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: How to retain previous values in graph? QWT

    Sorry gfor inconvenience and thanks for ur concern


    Sir i have used setSample() but its not working with timer my graphs it not even reploting
    what should i do kindly help

    thank

  8. #8
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to retain previous values in graph? QWT

    whether you use "setSamples" or "setRawSamples" has absolutely nothing to do with your timer. did you debug if "timerEvent" gets called?

  9. The following user says thank you to FelixB for this useful post:

    maarvi (25th March 2011)

  10. #9
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: How to retain previous values in graph? QWT

    thanks alot sir my this problem is solved u are awesome..

    but kindly tell me is there a way by which my to points get joined after 10 sec as now my two line get joined after 10 sec
    thanks you kindly help me

  11. #10
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to retain previous values in graph? QWT

    I'm sorry, I don't understand what you mean with "join two points". can you explain a bit more detailed?

  12. #11
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: How to retain previous values in graph? QWT

    sir i mean that i have some points like (0,0) (30, 200) ,(60,150)........ so one i want to plot the graph i want that my graph should appear like moving graph in which joins two points for eg (30,200) to (60 ,150) gradually and then join the next two points

    should i have to insert timer in my setSample if yes then how or what else i could do

    thanks so much

  13. #12
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to retain previous values in graph? QWT

    that sounds quite complicated. I have no idea how to do that at the moment. is the time between two points fixed? e.g. do you want to reach the next point always after x seconds? or is it dependant of the distance between the points, e.g. very short from (0,0) to (1,1) and very long time from (1,1) to (100,100)?

  14. #13
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: How to retain previous values in graph? QWT

    sir actually the distance alond x axis is fixed.the interval is 30 but y axis changes. and time should be same no need that for longer distance more time required

    thanks

Similar Threads

  1. can not go back to the previous window
    By xhsoldier in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2010, 05:45
  2. Replies: 1
    Last Post: 5th October 2010, 17:08
  3. Printing Values of the mouse position in a graph
    By soumyadeep_pan in forum Qwt
    Replies: 4
    Last Post: 22nd May 2009, 13:17
  4. Replies: 1
    Last Post: 22nd May 2008, 15:10
  5. Replies: 1
    Last Post: 21st March 2006, 12:54

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.