Results 1 to 10 of 10

Thread: QwtScaleDraw is not update in realtime graph

  1. #1
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default QwtScaleDraw is not update in realtime graph

    Hi,,
    I've implemented QwtScaleDraw to make a realtime graph like qwt example(cpu usage example):

    Qt Code:
    1. class TimeScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. TimeScaleDraw(const QTime &base):
    5. baseTime(base)
    6. {
    7. }
    8. virtual QwtText label(double v) const
    9. {
    10. QTime upTime = baseTime.addMSecs((int)v);
    11. return upTime.toString();
    12. }
    13.  
    14. QTime baseTime;
    15. };
    To copy to clipboard, switch view to plain text mode 

    I want to update baseTime to current time in every timer interval instead of adding to the array in every cycle.

    i call setAxisScale(QwtPlot::yLeft,timeData[INTERVAL-1],timeData[0]) in every cycle but the timeData array is held to be fix (is 0 to 60 for 60 data to be plotted).)

    Actually i want to my array(data of y axis) be fixed but baseTime will update in every cycle.
    When i do that the labels are not changing. actually the label function is not calling because when i call setAxisScale in timer scale the scale seems to be constant but because the basetime is changing so it must update itself!!

    How can i make this class to update itslef(call the label function whenever i call setAxisScale(QwtPlot::yLeft,timeData[INTERVAL-1],timeData[0]))( the timeData array is fix))
    Last edited by alizadeh91; 3rd September 2012 at 15:33.

  2. #2
    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: QwtScaleDraw is not update in realtime graph

    See QwtAbstractScaleDraw::invalidateCache: http://qwt.sourceforge.net/class_qwt...05aa5295409aa6

    Uwe

  3. #3
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtScaleDraw is not update in realtime graph

    Thanks Uwe, As i said i override it but the problem is when i want to send current time to its implemented class(QwtScaleDraw) and when my array for y axis is fix and is not changing the y-axis also is not changing and updating. But i don't understand how to do that?

    Forget to say my graph is vertically so i said y-axis!!


    Added after 5 minutes:


    Uwe, What i want to do : I've add QwtPlotGrid to realtime example of qwt. And the girds will moving as time. i want to fix labels to don't move as time. So i want instead of incrementing the array in timer, send current time in timer and add it by a constant array.
    Last edited by alizadeh91; 3rd September 2012 at 20:12.

  4. #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: QwtScaleDraw is not update in realtime graph

    Quote Originally Posted by alizadeh91 View Post
    As i said i override it ...
    What has nothing to do with my link about QwtAbstractScaleDraw::invalidateCache ...

    Qt Code:
    1. class TimeScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. ....
    5.  
    6. void setBaseTime( const QTime &time )
    7. {
    8. m_baseTime = time;
    9. invalidateCache();
    10. }
    11.  
    12. ....
    13. private:
    14. QTime m_baseTime;
    15. };
    To copy to clipboard, switch view to plain text mode 

    Then the next replot will update the tick labels.

    Uwe

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

    alizadeh91 (4th September 2012)

  6. #5
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtScaleDraw is not update in realtime graph

    You are my hero man

  7. #6
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtScaleDraw is not update in realtime graph

    I'm sorry uwe!! but it won't work!!! it's not rescalling the axis.??

  8. #7
    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: QwtScaleDraw is not update in realtime graph

    What it does is to return different labels for the same values depending on the base time - without rescaling.
    When you want to rescale I didn't get what you want to do.

    Uwe

  9. #8
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtScaleDraw is not update in realtime graph

    I've implemented the way you suggested with invalidateCache(); But the problem is that when i run the program the real-time-axis is not updating!!! while the basebase time is updating and with that invalidateCache will be called. In the meanwhile when i for example open a dialog on plotter or make a right click on the graph, the real-time-axis will be updated!!! seems some things must be triggered !!! the replot didn't help me either.


    Added after 20 minutes:


    I've modified the cpuplot example the way i want it and attach it. i'll be very appreciated if take look at it. I've modified the cpuplot file. besides the attached project i've provided snapshots of the changes relative to native code:
    sorry i forgot to attach:
    cpuplot.cppcpuplot.h
    Qt Code:
    1. class TimeScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. TimeScaleDraw(const QTime &base):
    5. baseTime(base)
    6. {
    7. }
    8. virtual QwtText label(double v) const
    9. {
    10. QTime upTime = baseTime.addSecs((int)v);
    11. return upTime.toString();
    12. }
    13.  
    14. void setBaseTime( const QTime &time )
    15. {
    16. baseTime = time;
    17. invalidateCache();
    18. }
    19.  
    20. private:
    21. QTime baseTime;
    22. };
    23.  
    24. //timer event in cpuplot class
    25. void CpuPlot::timerEvent(QTimerEvent *)
    26. {
    27. for ( int i = dataCount; i > 0; i-- )
    28. {
    29. for ( int c = 0; c < NCpuData; c++ )
    30. {
    31. if ( i < HISTORY )
    32. data[c].data[i] = data[c].data[i-1];
    33. }
    34. }
    35.  
    36. cpuStat.statistic(data[User].data[0], data[System].data[0]);
    37.  
    38. data[Total].data[0] = data[User].data[0] +
    39. data[System].data[0];
    40. data[Idle].data[0] = 100.0 - data[Total].data[0];
    41.  
    42. if ( dataCount < HISTORY )
    43. dataCount++;
    44. //---I've commented below codes to instead of incrementing array send current time
    45. // for ( int j = 0; j < HISTORY; j++ )
    46. // timeData[j]++;
    47.  
    48. scaleDraw->setBaseTime(currentTime);
    49.  
    50.  
    51.  
    52. setAxisScale(QwtPlot::xBottom,
    53. timeData[HISTORY - 1], timeData[0]);
    54.  
    55. for ( int c = 0; c < NCpuData; c++ )
    56. {
    57. data[c].curve->setRawSamples(
    58. timeData, data[c].data, dataCount);
    59. }
    60.  
    61. replot();
    62. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by alizadeh91; 5th September 2012 at 13:09.

  10. #9
    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: QwtScaleDraw is not update in realtime graph

    As the modification of the "scales" is not known to the scale widget you have to help with the update:

    Qt Code:
    1. scaleDraw->setBaseTime(cpuStat.upTime());
    2. axisWidget( QwtPlot::xBottom )->update();
    3. replot();
    To copy to clipboard, switch view to plain text mode 
    HTH,
    Uwe

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

    alizadeh91 (5th September 2012)

  12. #10
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtScaleDraw is not update in realtime graph

    That is exactly what i was looking for
    You've saved a lot of my time.
    Thanks again

Similar Threads

  1. Refreshing a Custom QwtScaleDraw
    By grantbj74 in forum Qwt
    Replies: 6
    Last Post: 28th March 2012, 05:20
  2. Replies: 1
    Last Post: 13th October 2011, 16:52
  3. Replies: 2
    Last Post: 14th September 2011, 07:53
  4. QwtScaleDraw align label to xaxis
    By kja in forum Qwt
    Replies: 1
    Last Post: 21st November 2010, 19:55
  5. Replies: 1
    Last Post: 14th October 2010, 18:56

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.