Results 1 to 9 of 9

Thread: Real time data plotting using Qwt

  1. #1
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Real time data plotting using Qwt

    Hello every one, i am working on a plotting software where i have to plot some temperature data. I wrote the program but i am missing something i guess.. I don't have the temperature data plotted..

    Qt Code:
    1. #include "mux_selection.h"
    2. mux_selection::mux_selection(QWidget *parent)
    3. : QDialog(parent)
    4. , m_curve(0)
    5. , curve(0)
    6. {
    7. minX =0;
    8. maxX =60;
    9. QwtPlotGrid *grid = new QwtPlotGrid();
    10. //enable the x and y axis lines
    11. grid->enableX(true);
    12. grid->enableY(true);
    13.  
    14. timerdrawplot = new QTimer(this);
    15.  
    16. //set the X and Y division and scale to that of the channels
    17. grid->setXDiv(*(myPlot->axisScaleDiv(QwtPlot::xBottom)));
    18. grid->setYDiv(*(myPlot->axisScaleDiv(QwtPlot::yLeft)));
    19. grid->attach(myPlot);
    20. myPlot->setCanvasBackground("lightyellow");
    21.  
    22. myPlot->setTitle("Data Receiver");
    23. myPlot->setAxisTitle(QwtPlot::xBottom, "Time in Seconds");
    24. myPlot->setAxisScale(QwtPlot::xBottom, 0, 60);
    25. myPlot->setAxisTitle(QwtPlot::yLeft, "<FONT color=#0000ff face=Arial size=4><B> Temperature in C° </FONT>");
    26. myPlot->setAxisScale(QwtPlot::yLeft, -200, +200);
    27. myPlot->setAutoReplot(true);
    28. }
    To copy to clipboard, switch view to plain text mode 

    i am calling the plot function when i click the plot button using a timer every 1000 mili sec. right now i am retrieving one channel data from the db and trying to display it.
    Qt Code:
    1. void mux_selection::plot()
    2. {
    3. m_vx.clear(); // QVector<double> m_vx,m_vy;
    4. m_vy.clear();
    5.  
    6. QSqlQuery q("select "+ colNames +" from tempdata where rowid = " + QString::number(rowcnt)); // colNames = channel1;
    7.  
    8. while(q.next())
    9. {
    10. m_vx.push_back(q.value(0).toDouble());
    11. m_vy.push_back(q.value(1).toDouble());
    12. }
    13.  
    14. if(m_vx.count()!= 0)
    15. {
    16. rowcnt++;
    17. }
    18. qDebug()<<m_vy<<m_vx<<rowcnt;
    19. if (!m_curve)
    20. {
    21. m_curve = new QwtPlotCurve();
    22. m_curve->setPen(QPen(Qt::black, 2,t::SolidLine));
    23. m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
    24. }
    25.  
    26. myPlot->setAxisScale( QwtPlot::xBottom, minX , maxX );
    27. myPlot->replot();
    28. }
    To copy to clipboard, switch view to plain text mode 

    i am able to figure out where i am going wrong...

    Thank you


    Added after 1 55 minutes:


    hello is there anything wrong in the program. . ? pls help me out not able to know where i am going wrong.
    thanks so much
    Last edited by nagabathula; 15th March 2011 at 17:44.

  2. #2
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Real time data plotting using Qwt

    somebody please help me out.. not able to know where i am going wrong.. I have been trying different other things but not able to plot the data from the data base.

    regards

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

    Default Re: Real time data plotting using Qwt

    have a look at this snippet:

    Qt Code:
    1. if (!m_curve)
    2. {
    3. m_curve = new QwtPlotCurve();
    4. m_curve->setPen(QPen(Qt::black, 2,t::SolidLine));
    5. m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
    6. }
    To copy to clipboard, switch view to plain text mode 

    m_curve is a member of your class, you initialize it with 0. The first time "plot()" gets called, you assign a "new QwtPlotCurve" to m_curve. What happens when "plot()" gets called next time?

    Felix

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

    nagabathula (18th March 2011)

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Real time data plotting using Qwt

    Also use autoscaling for the moment to avoid, that the values are somewhere outside the visible area. It might be a good idea to check the samples, that are assigned to the curve.

    Uwe

  6. The following user says thank you to Uwe for this useful post:

    nagabathula (18th March 2011)

  7. #5
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Real time data plotting using Qwt

    Hello thank you for the reply.. I did check on the samples if the data is present the data is present the Time Interval and the channel data is there.. But i still don have the curve plotted.

    Qt Code:
    1. qDebug()<<m_vx<<m_vy<<colNames;
    2. if (m_vx.count() <= 0) // no data no curve.
    3. return;
    4. m_lastTime = (int)m_vx[m_vx.count() + 1];
    5. if (!m_curve)
    6. {
    7. m_curve = new QwtPlotCurve();
    8. m_curve->setPen(QPen(Qt::red));
    9. m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
    10. }
    11. m_curve->attach(myPlot);
    12. m_curve->setPen(QPen(Qt::red));
    13. m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
    14. }
    To copy to clipboard, switch view to plain text mode 
    but this does't work .. as FelixB told i did not plot the data after the initial call so i have set the pen and Data after it. But still i don have a curve plotted.

    regards

  8. #6
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Real time data plotting using Qwt

    hey i solved the problem.. Thanks for the suggestions.

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

    robotics (5th July 2011)

  10. #7
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Real time data plotting using Qwt

    So how did you fix the problem?

  11. #8
    Join Date
    May 2011
    Posts
    39
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Real time data plotting using Qwt

    hey would you please post your final solution please............
    I badly need it

  12. #9
    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: Real time data plotting using Qwt

    Notice that in the original code, the curve was never "attached" to the plot. So even though the curve was created correctly, the plot was never told about it, so of course it never is drawn.

    In the revised code (March 16), attach is called, but the code is still incorrect: attach is called every time the plot() method executes. It only needs to be called once, in the section of code that creates the curve ( if ( !m_curve )... ).

    Likewise, the pen color never changes, so it is not necessary to set the pen every time plot() is executed. The only call needed each time plot() is executed is to update the data pointers.

    And in this particular case, since it looks like the mux_selection class is keeping its own copy of the data (m_vx, m_vy), the setRawData() method should be used instead of setData(), since setData will make another copy of the data. If the data arrays are large, this will cause performance problems because of all the extra memory allocation and copying in the curve.

Similar Threads

  1. real time data display
    By hammer256 in forum Qt Programming
    Replies: 13
    Last Post: 25th March 2013, 16:47
  2. Replies: 1
    Last Post: 23rd September 2010, 20:16
  3. Replies: 1
    Last Post: 3rd December 2009, 14:23
  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

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.