Results 1 to 5 of 5

Thread: QwtPlotcurve multiple curves

  1. #1
    Join Date
    Apr 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QwtPlotcurve multiple curves

    Hi,

    I would like to plot multiple curves on one qwtplot object.



    Qt Code:
    1. QwtPlotCurve* mycurve = new QwtPlotCurve("curve1");
    2. QwtPlotCurve* mycurve2 = new QwtPlotCurve("curve2");
    3.  
    4. QwtPointSeriesData* myData = new QwtPointSeriesData;
    5. QVector<QPointF>* samples = new QVector<QPointF>;
    6. samples->push_back(QPointF(time->at(0), samplesPerUser[0]));
    7. //creating histogram
    8. for (int i=1; i<30; i++) {
    9. samples->push_back(QPointF((time->at(i) + time->at(i+1)) / 2, samplesPerUser[i]));
    10. samples->push_back(QPointF((time->at(i) + time->at(i+1)) / 2, samplesPerUser[i+1]));
    11. }
    12. samples->push_back(QPointF(time->at(30), samplesPerUser[30]));
    13.  
    14. myData->setSamples(*samples);
    15. mycurve->setData(myData);
    16. mycurve->attach(plot);
    17.  
    18. QwtPointSeriesData* myData2 = new QwtPointSeriesData;
    19. QVector<QPointF>* samples2 = new QVector<QPointF>;
    20. samples->push_back(QPointF(time->at(0), samplesPerUser2[0]));
    21. //creating histogram
    22. for (int i=1; i<30; i++) {
    23. samples2->push_back(QPointF((time->at(i) + time->at(i+1)) / 2, samplesPerUser2[i]));
    24. samples2->push_back(QPointF((time->at(i) + time->at(i+1)) / 2, samplesPerUser2[i+1]));
    25. }
    26. samples->push_back(QPointF(time->at(30), samplesPerUser2[30]));
    27.  
    28. myData->setSamples(*samples2);
    29. mycurve->setData(myData2);
    30. //making the second curve red
    31. mycurve2->setPen(QPen(Qt::red));
    32.  
    33. mycurve2->attach(plot);
    To copy to clipboard, switch view to plain text mode 

    The problem is that I can see only the second curve, not the first one. I'm not sure whether creating 2 QwtPlotCurve object and attaching them to the plot is a right approach.

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotcurve multiple curves

    Avoid Copy & Paste, that's where you'll make most mistakes.

    In line #29 by mistake you're setting your second data set on first curve.

    And creating two curves and attaching them to the plot is the right approach

  3. #3
    Join Date
    Apr 2012
    Posts
    10
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotcurve multiple curves

    but how to create two dynamic curves in one plot canvas with different types of data?
    for example, the data for the first curve may be sampled from the ADC device,and the data for the second curve is from mathematical function like square wave function?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlotcurve multiple curves

    All of the code that you provided looks correct to me, except line 29 (which has already been pointed out to you). This line should be

    Qt Code:
    1. mycurve2->setData(myData2);
    To copy to clipboard, switch view to plain text mode 

    (Note: mycurve2, not mycurve).

    You probably have some major memory leaks, because I think you are making new QVector instances when you should simply create them on the stack. But get the curves displayed first, then fix the memory problems.

  5. #5
    Join Date
    Apr 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlotcurve multiple curves

    Thanks all. It works now.

Similar Threads

  1. Replies: 6
    Last Post: 14th January 2011, 16:40
  2. Select multiple curves
    By aimsc in forum Qwt
    Replies: 2
    Last Post: 30th October 2009, 10:45
  3. Replies: 2
    Last Post: 1st August 2009, 11:44
  4. Multiple curves on top of each other
    By jmsbc in forum Qwt
    Replies: 2
    Last Post: 15th July 2009, 19:46
  5. Replies: 2
    Last Post: 14th April 2008, 11:03

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.