Results 1 to 14 of 14

Thread: How to make the x-Bottom scale fixed.

  1. #1
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question How to make the x-Bottom scale fixed.

    Hi friends i have a problem with my Plotting program. I have a db in which i save the data i have acquired. Initially the db is empty with no values. I need to have a fixed time scale from 0 to 60 seconds. Now once i click the start acquisition button i have to start acquiring data from a external device and save it to the DB and plot it. Its real time plotting. so i have to plot as i acquire the data. But the x-bottom scale changes according to the amount of data present in the db.
    example - If i have only 4 values acquired to the DB the scale is changed to [0 to 3]. It looks like the image i have attached named (3).

    If have say 40 values are added to the db the scale is changed to 35. It looks like the image i have attached named (35)

    I actually wanted the scale to stay fixed to 60 and the graph to grow from the initial value as the data keeps adding in the graph has to grow gradually.Some thing like the snapshot (60) i have attached.

    what do i need to do so that the x-bottom scale is fixed and the data to be plotted with out changing the scale irrespective of the amount of data present in the DB like in the image named (60).


    Thank You
    Please looking forward for a reply.
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make the x-Bottom scale fixed.

    Hi friends how do i fix the the x-bottom size of a qwt plot widget.
    Qt Code:
    1. myPlot->setTitle("Data Acquisition");
    2. myPlot->setAxisTitle(QwtPlot::xBottom, "System time");
    3. myPlot->setAxisScale(QwtPlot::xBottom, 0, 60);
    4. myPlot->setAxisTitle(QwtPlot::yLeft, "Bar");
    5. myPlot->setAxisScale(QwtPlot::yLeft, 0, 100);
    6. myPlot->setAutoReplot(true);
    To copy to clipboard, switch view to plain text mode 

    I am using the above code to set the x-bottom scale from 0 to 60. But when i click the start plotting button the bottom scale is changed according to the number of values present in the db. I wanted the scale to stay at 0 to 60 only and the graph to plot according to the number of values present in the db.I am able to retrive data from the db every second but my only problem is the scale which changes i want it to be fixed. How can i do that. ??


    Thank You

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

    Default Re: How to make the x-Bottom scale fixed.

    The code above is already what you need to do. Obviously someone else is also changing the scale or re-enables autoscaling.

    Uwe

  4. #4
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Problem Solved.

    Hi uwe problem solved. Thank You for the reply.

    In my plot function i had this
    Qt Code:
    1. curve->setPen(QPen(Qt::red));
    2. //myPlot->setAxisScale(QwtPlot::xBottom, m_vx[0], m_vx[m_vx.count() - 1]);
    To copy to clipboard, switch view to plain text mode 

    Just commented the second line and Bingo. !! But once the graph reaches the x-bottom point 60. I wanted the graph to be cleared and the next graph which again starts with 0 to be started fresh again. I have the data in the db in this format ..
    Qt Code:
    1. TIME DATA
    2. 0 21
    3. 1 24
    4. 2 28
    5. 3 20
    6. . .
    7. . .
    8. . .
    9. 60 24
    10. 0 22
    11. 1 31
    12. 2 26
    13. 3 23
    14. 4 19
    15. . .
    16. . .
    17. . .
    18. 60 27
    To copy to clipboard, switch view to plain text mode 
    Time keeps repeating from 0 to 60 so once the graph is plotted from 0 to 60 it has to be cleared and the graph has to start again from next 0 to 60 and so on. I am not able to figure out how to clear the graph which is displayed on the screen once it reaches 60.Because of this once the graph reaches 60 weird things happen. How should i clear the graph from the screen uwe. ?

    Thank You

  5. #5
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Clearing Plot. ??

    Hi uwe i used the clear slot to clear the plot on a button clicked.
    Qt Code:
    1. void graphplotting::on_pushButton_clicked()
    2. {
    3. myPlot->clear();
    4. }
    To copy to clipboard, switch view to plain text mode 

    But i get a exception error. I tried so much but i still get the same error.
    where am i going wrong uwe. !!!


    Thank You
    Attached Images Attached Images

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clearing Plot. ??

    Such error appears when you try to access unallocated memory.

    When you invoke QwtPlot::clear() it deletes all attached curves, so this error might appear if you access "curve" after push button has been clicked.
    Last edited by jacek; 7th June 2008 at 00:57. Reason: typo

  7. #7
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make the x-Bottom scale fixed.

    Hi jacek I have looked so much for an example which shows how to clear plots. But cud't find any. I have been tryin since yeste with this problem but cud't slove it. Pls tell me what i have to do to clear this error.



    Thank You

  8. #8
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make the x-Bottom scale fixed.

    Hi some one pls give me an example to clear( ) a plot . I don't find any on the net. !!!


    Thank You

  9. #9
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question myPlot->Clear() not yet solved. !!!

    Hi every one,

    I tried so much , I tried the qwt example realtime_plot example in which there is a clear function . Into my program but still i get a exception. Some one pls help me i am really stuck at this place past 2 dazz. !! Tried all the things i cud.But no o/p . Give me a example or tell me how to use the qwtPlot->clear(); in the program.


    Thank You

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: myPlot->Clear() not yet solved. !!!

    Where do you use "curve" varaible?

  11. #11
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re:Referesh Graph . ?

    Hello jacek Thankx for the reply, I solved my problem .
    Qt Code:
    1. void RS232_Receive::retrive()
    2. {
    3. {
    4. m_curve = new QwtPlotCurve("myPlot");
    5. myPlot->clear();
    6. myPlot->replot();
    7. //draw();
    8. }
    9. draw();
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    I did this but once i clear the curve i wanted to call the draw function so that the next values is plotted from start after the present graph is cleared from the screen. But i am not getting it, the new curve is not plotted. !! Where am i going wrong .

    Thank You jacek

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Referesh Graph . ?

    myPlot->clear() deletes the existing curve, so you have to create a new one and attach it to the plot.

    Alternatively you can simply remove all the data from the curve and invole myPlot->replot() instead of myPlot->clear().

  13. #13
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Plotting a Curve after Clearing the Curve not happening.

    Hi friends i solved my Clear problem. I am able to clear the curve but now once the curve is cleared the next curve is not plotted. The screen stays blank. I am clearing the curve once the count of 60 is completed. And wanted the next curve to sart plotting but there seems to be a problem after the curve is cleared the next new curve is not plotting.

    Qt Code:
    1. void graphplot::retrive()
    2. {
    3. int a=(rand()%10)+10;
    4. QString j(QString::number(a));
    5. if (count<60)
    6. {
    7. QSqlQuery m_query;
    8. QString sq1("select max(s_x)+1 from newtest_table");
    9. m_query.exec(sq1);
    10. QString sq("INSERT INTO newtest_table values(%1,%2)");
    11. sq = sq.arg(count)
    12. .arg(j);
    13. m_query.exec(sq);
    14. count++;
    15. textBrowser->append(j);
    16. textBrowser->ensureCursorVisible();
    17.  
    18. }
    19. else
    20. {
    21. count=0;
    22. retrive();
    23.  
    24. myPlot->clear();// I am trying to clear and go to the next value of the plot and start the graph plot from 0 again here.
    25. myPlot->replot();
    26. m_curve = 0;
    27. m_curve = new QwtPlotCurve("myCurve");
    28. m_curve->attach(myPlot);
    29. draw(); // I am trying to call the draw so that the next curve is plotted.But the new curve does not plot.
    30. }
    31. }
    32. void graphplot::draw()
    33. {
    34. QSqlQuery q("SELECT s_x, s_y FROM newtable ");
    35. m_vx.clear();
    36. m_vy.clear();
    37. if(q.exec())
    38. {
    39. if (q.first())
    40. {
    41. do
    42. {
    43. m_vx.push_back(q.value(0).toDouble());
    44. m_vy.push_back(q.value(1).toDouble());
    45. } while(q.next());
    46. }
    47. if (m_vx.count() <= 0) // no data no curve.
    48. return;
    49. m_lastTime = (int)m_vx[m_vx.count() - 1];
    50. if (! m_curve)
    51. {
    52. m_curve = new QwtPlotCurve();
    53. m_curve->attach(myPlot);
    54. }
    55. m_curve->setPen(QPen(Qt::red));
    56. m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
    57. myPlot->replot();
    58. qDebug("m_timer->start(999)");
    59. m_timer->start(999);
    60. }
    61. }
    To copy to clipboard, switch view to plain text mode 

    pls tell me where i am going wrong.


    Thank You

  14. #14
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Plotting a Curve after Clearing the Curve not happening.

    Hi jacek i even tried what you asked me to myPlot->replot(), But this does't seem to work there is no change in the curve it just plots till 60 and stays there it does't clear or replot.When i use myPlot->clear it plots till 60 and clears there but the next curve is not plotted.The qwt plot widget stays blank.
    Pls tell me what is the mistake i am doing. jacek


    Thank you
    Last edited by Tavit; 12th June 2008 at 17:49.

Similar Threads

  1. Replies: 7
    Last Post: 15th November 2007, 17:19
  2. How to make headers fixed sized? (QTableWidget)
    By macias in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2007, 15:57
  3. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

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.