Results 1 to 20 of 33

Thread: display a plot point by point

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default display a plot point by point

    hello
    i finally downloaded qwt from svn and everything is ok (Qt 4.5 ,qwt 5.3.0,windows xp)
    now i need to display a plot point by point ,so i tried to create a retard with Qtimer ,but it doesn't work !

    no execution or complilation errors but i haven't the result i'm expecting
    it's my first program with qwt ,i'm following the pdf given with qwt 5.1.1
    the documentation for qwt 5.1.1 still useful ?

    thanks in advance
    Last edited by oswalidos; 9th March 2009 at 20:49.

  2. #2
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    maybe i'm not clear
    i simply want to see plot painting point by point because i'm working on a "real-time" application ,points will be available while my system is running ,so i plan to use Qthread to synchronize tasks .
    now i need to know how can i control displaying plots ?
    can i find signals or create signals to do such thing ?
    thanks for your help

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: display a plot point by point

    Can we see the code?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    i just tried a code which stored data first ,after it display the curve

    Qt Code:
    1. #include <QtGui>
    2. #include <qwt_plot.h>
    3. #include <qwt_plot_curve.h>
    4. #include <qwt_plot_marker.h>
    5. #include <qwt_plot_curve.h>
    6. #include <qwt_legend.h>
    7. #include <qwt_series_data.h>
    8. #include <qwt_text.h>
    9. #include <math.h>
    10.  
    11. class Plot : public QwtPlot
    12. {
    13. public:
    14. Plot();
    15. };
    16.  
    17. Plot::Plot()
    18. {
    19. double x[100];
    20. double y1[100];
    21. double y2[100];
    22.  
    23. for(int i=0;i<100;i++){
    24. x[i]=i;
    25. y1[i]=i*i;
    26. y2[i]=i;
    27. }
    28.  
    29.  
    30. setTitle("Vitesse et angle de braquage en fonction du temps");
    31. insertLegend(new QwtLegend(), QwtPlot::RightLegend);
    32.  
    33. // Set axes
    34. setAxisTitle(xBottom, "Temps");
    35. setAxisScale(xBottom, 0.0, 100);
    36.  
    37. setAxisTitle(yLeft, "");
    38. setAxisScale(yLeft, 0.0, 100);
    39.  
    40. // add curves
    41. QwtPlotCurve *curve1 = new QwtPlotCurve("Vitesse");
    42. curve1->setPen(QPen(Qt::green));
    43. curve1->attach(this);
    44. curve1->setData(x, y1, 100);
    45.  
    46. QwtPlotCurve *curve2 = new QwtPlotCurve("Angle de Braquage");
    47. curve2->setPen(QPen(Qt::red));
    48. curve2->attach(this);
    49. curve2->setData(x, y2, 100);
    50.  
    51. // ...a horizontal line ...
    52. mY->setLabel(QString::fromLatin1("t ( ms )"));
    53. mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    54. mY->setLineStyle(QwtPlotMarker::HLine);
    55. mY->attach(this);
    56.  
    57. // ...a vertical line ...
    58. mX->setLabel(QString::fromLatin1("V ( m/s ) ,Ang ( rad/s )"));
    59. mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    60. mX->setLineStyle(QwtPlotMarker::VLine);
    61. mX->attach(this);
    62.  
    63. }
    64.  
    65.  
    66. int main(int argc, char **argv)
    67. {
    68. QApplication a(argc, argv);
    69.  
    70. Plot *myPlot = new Plot();
    71. myPlot->autoRefresh();
    72.  
    73. myPlot->resize(600,400);
    74. myPlot->show();
    75.  
    76. return a.exec();
    77. }
    To copy to clipboard, switch view to plain text mode 

    i want to change this code to display the curve step by step from (0,0) until (n,m) while time progressing !

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: display a plot point by point

    So where is your timer code?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    i don't know where should i put timer .
    i'm asking how can i put timer ?
    i may should use other classes not Qwtplot cuz it needs the data stored to display curves .
    i tried with timer somewhere but it doesn't seem to work !
    i think i have to use others classes or some signals to control painting process .

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: display a plot point by point

    You should start a timer somewhere in your code and connect its timeout() signal to a custom slot that you have to implement. Inside the slot simply add more data to the curves.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    oswalidos (10th March 2009)

  9. #8
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    all data is fixed in constructor and can't be anywhere else .
    i think constructor can't be dynamic ,it's fixed since we instance an object from its class .
    if constructor still running when application is running that's mean is using more than thread ,that's can be right ?
    can i call constructor many times to change object's value and display it using timer ? i don't think so !

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: display a plot point by point

    In the constructor you can store the data in some array. Then you can add the data to the plot in some other place (like a slot).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    oswalidos (10th March 2009)

  12. #10
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    thanks for your help ,
    i'll try but logically data in constructor should be given only one time .

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: display a plot point by point

    I think you don't understand me. You can keep the data in two places - one of them is initialized and filled with data in the constructor. The other is the plot itself that is fed with the data from the first container using a timer.

    Here is a skeleton of a code doing what I mean:
    Qt Code:
    1. X::X(){
    2. for(int i=0;i<100;i++){
    3. x[i]=i;
    4. y1[i]=i*i;
    5. y2[i]=i;
    6. }
    7. curve1 = new QwtPlotCurve("Vitesse"); // curve1 is a member variable
    8. currentPointPosition = 1; // currentPointPosition is a member variable
    9. updateData();
    10. QTimer *timer = new QTimer(...);
    11. connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
    12. timer->start(500);
    13. //...
    14. }
    15.  
    16. void X::onTimeout(){
    17. currentPointPosition++;
    18. if(currentPointPosition>100) currentPointPosition = 1;
    19. updateData();
    20. }
    21.  
    22. void X::updateData(){
    23. curve1->setData(x, y1, currentPointPosition);
    24. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. The following user says thank you to wysota for this useful post:

    oswalidos (10th March 2009)

Similar Threads

  1. Replies: 3
    Last Post: 20th April 2006, 11:21

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.