Results 1 to 3 of 3

Thread: cannot see the curve, after attaching it to Plot

  1. #1
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default cannot see the curve, after attaching it to Plot

    Hello,

    I have created a qwtPlotCurve and attached it to a QwtPlot, but I cannot see any curve there. Please help me to get it visible.

    In this function I create the curves:

    Qt Code:
    1. void OscillationGRN::plotCurves(){
    2.  
    3. for(int j = 0; j < ListOfPlots.size(); ++j){
    4. //create new Curve
    5. QwtPlotCurve *newCurve = new QwtPlotCurve();
    6. newCurve->setPen(QColor(Qt::red));
    7. newCurve->setStyle(QwtPlotCurve::Lines);
    8. newCurve->setCurveAttribute(QwtPlotCurve::Fitted);
    9.  
    10. double range[] ={0,20};
    11. double step = 0.1;
    12. // copy the data into the curves
    13. newCurve->setData(CurveData(range, step));
    14. newCurve->attach(ListOfPlots[j]);
    15.  
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    whereby
    Qt Code:
    1. QVector<QwtPlot*> ListOfPlots;
    To copy to clipboard, switch view to plain text mode 
    is and CurveData is a class inherited from QwtData:

    Qt Code:
    1. class CurveData: public QwtData
    2. {
    3. // The x values depend on its index and the y values
    4. // can be calculated from the corresponding x value.
    5. // So we don't need to store the values.
    6. // Such an implementation is slower because every point
    7. // has to be recalculated for every replot, but it demonstrates how
    8. // QwtData can be used.
    9.  
    10. public:
    11. CurveData( double rang1[2], double step)
    12. {
    13. rangeX[0]= rang1[0]; rangeX[1] = rang1[1];
    14. range = (rangeX[1] - rangeX[0])/step;
    15. if(range<0){
    16. range = range *(-1);
    17. }
    18. d_size = size_t(range);
    19. cout << "range = "<< range << " , d_size= " << d_size<< endl; // <<<<<<<< this output IS seen in console
    20. }
    21.  
    22. virtual QwtData *copy() const
    23. {
    24. return new CurveData(*this);
    25. }
    26.  
    27. virtual size_t size() const
    28. {
    29. return d_size;
    30. }
    31.  
    32. virtual double x(size_t i) const
    33. {
    34. cout << "x = " << rangeX[0] + i*((rangeX[1]- rangeX[0])/range) << endl; // <<<<<<<< this output is NOT seen in console
    35. // here the array with x values will be produced
    36. return rangeX[0] + i*((rangeX[1]- rangeX[0])/range);
    37. }
    38.  
    39. virtual double y(size_t i) const
    40. {
    41. cout << "y = " << sin(2*3.1415926*x(i)/T)+1.0 << endl; // <<<<<<<< this output is NOT seen in console
    42. return sin(2*3.1415926*x(i)/T)+1.0;
    43. }
    44. private:
    45. size_t d_size;
    46. double range;
    47. double rangeX[2];
    48.  
    49. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: cannot see the curve, after attaching it to Plot

    by the way, if I generate x and y data by myself, it does not work, too.

    Qt Code:
    1. void OscillationGRN::plotCurves(){
    2.  
    3. for(int j = 0; j < ListOfPlots.size(); ++j){
    4. //create new Curve
    5. QwtPlotCurve *newCurve = new QwtPlotCurve();
    6. newCurve->setPen(QColor(Qt::red));
    7. newCurve->setStyle(QwtPlotCurve::Lines);
    8. newCurve->setCurveAttribute(QwtPlotCurve::Fitted);
    9. const unsigned Size=200;
    10. double xval[Size];
    11. double yval[Size];
    12. double ti=0;
    13. for(unsigned i=0; i<Size; ++i){
    14. xval[i] = ti;
    15. yval[i] = sin(2*3.1415926*ti/T)+1.0;
    16. ti= ti+0.1;
    17. }
    18.  
    19. newCurve->setRawData(xval,yval, Size);
    20. newCurve->attach(ListOfPlots[j]);
    21.  
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: cannot see the curve, after attaching it to Plot

    I'm sorry for the previous posts. I have made a big mistake forgeting to call "replot()"!

    Qt Code:
    1. ListOfPlots[j]->replot();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 9
    Last Post: 12th May 2014, 01:25
  2. Best way in Qt to plot curve per real-time reading?
    By Sheng in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2009, 22:33
  3. Replies: 4
    Last Post: 9th January 2009, 11:57
  4. attaching user data pointer to images in QTextEdit
    By Workeml in forum Qt Programming
    Replies: 0
    Last Post: 7th November 2008, 20:06
  5. SMTP tag for attaching file
    By joseph in forum General Programming
    Replies: 11
    Last Post: 10th July 2007, 04:41

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.