Results 1 to 4 of 4

Thread: [Solved]Unable to calculate proper intervals for time plot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2013
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default [Solved]Unable to calculate proper intervals for time plot

    Hey,

    I've got this plot with a custom canvas, curve, legend and plotpicker. Everything works great. I'm trying to add date/time support on the x axis. This plot receives real time data and replots as new values arrive, x axis is time. For testing purposes I am firing off a signal every 1000ms that adds a point with a random [0,120] value on the y axis and the current time on the x axis. For the plot I am assigning the following for the scales:

    From the StockChart example:
    Qt Code:
    1. class DateScaleDraw: public QwtDateScaleDraw
    2. {
    3. public:
    4. DateScaleDraw(Qt::TimeSpec timeSpec):
    5. QwtDateScaleDraw( timeSpec )
    6. {
    7. setDateFormat(QwtDate::Millisecond, "hh:mm:ss:zzz\nddd dd MMM");
    8. setDateFormat(QwtDate::Second, "HH:MM:ss\nddd dd MMM");
    9. setDateFormat(QwtDate::Minute, "HH:MM\nddd dd MMM");
    10. setDateFormat(QwtDate::Hour, "MM:MM\nddd dd MMM");
    11. setDateFormat(QwtDate::Day, "ddd dd MMM yyyy");
    12. setDateFormat(QwtDate::Week, "Www");
    13. setDateFormat(QwtDate::Month, "MMM yyyy");
    14. setDateFormat(QwtDate::Year, "yyyy");
    15. }
    16.  
    17. };
    To copy to clipboard, switch view to plain text mode 

    Now:
    Qt Code:
    1. QwtDateScaleDraw *scaleDraw = new DateScaleDraw(Qt::UTC );
    2. QwtDateScaleEngine *scaleEngine = new QwtDateScaleEngine(Qt::UTC);
    3.  
    4. setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
    5. setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );
    To copy to clipboard, switch view to plain text mode 

    When my program starts the chart displays an empty canvas with the time scale starting at 1970, which is fine. However, as soon as data comes in from the timer the x axis readjusts to years, instead of seconds (how it should be, as far as I know) and the following happens:



    The points all get compressed on to the same line, since they are all only seconds apart and the axis is adjusting to years.

    How can I force a fixed interval between the points (say, 60 seconds/minutes/hours/etc), I already have the moving and scrolling code in place after this interval is set, I'm just unsure as to how to do it for time values.

    For non-time points I do this:
    Qt Code:
    1. setAxisScale(QwtPlot::xBottom, m_curves[0]->data()->size()-m_pointsToDisplay, m_curves[0]->data()->size());
    To copy to clipboard, switch view to plain text mode 
    Which gives me a nice interval of size m_pointsToDisplay, but it doesn't seem to work for the datetime engine.

    Thanks, OC.

    Edit: Nevermind, I got it. I did the following, for whomever is interested:

    Qt Code:
    1. double startx = data->sample(data->size()-m_pointsToDisplay).x();
    2. double endx = data->sample(data->size()-1).x();
    3. setAxisScale(QwtPlot::xBottom, startx, endx);
    To copy to clipboard, switch view to plain text mode 

    My data samples are in ms since epoch, so that worked well. Thanks anyhow, awesome work Uwe (In case you see this)
    Last edited by C403; 4th June 2013 at 10:08.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Unable to calculate proper intervals for time plot

    Date/Time scales are expecting values as "msecs since Epoch" , but the range you are setting for the xBottom scale has nothing to do with it. For translating date/time values into doubles ( and v.v ) see QwtDate.

    Uwe

    PS: When implementing the date/time classes I noticed, that there is another use case, where a scale has to display a time interval ( msecs since some start point ), what is unrelated to the real date/time. But as it was too late for Qwt 6.1 I decided to postpone this one for the next release.

  3. #3
    Join Date
    May 2013
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Unable to calculate proper intervals for time plot

    Quote Originally Posted by Uwe View Post
    Date/Time scales are expecting values as "msecs since Epoch" , but the range you are setting for the xBottom scale has nothing to do with it. For translating date/time values into doubles ( and v.v ) see QwtDate.

    Uwe

    PS: When implementing the date/time classes I noticed, that there is another use case, where a scale has to display a time interval ( msecs since some start point ), what is unrelated to the real date/time. But as it was too late for Qwt 6.1 I decided to postpone this one for the next release.
    I am sending my x axis values as QDateTime::currentMSecsSinceEpoch() (or an equivalent representation). As a side note: this function returns an int64, and failing to cast this to a double causes problems for QwtDate.

    I got my fixed scale working just fine, so once again, thanks.

    -OC

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

    Default Re: Unable to calculate proper intervals for time plot

    Quote Originally Posted by C403 View Post
    As a side note: this function returns an int64, and failing to cast this to a double causes problems for QwtDate.
    Yes an int64 is no double and can't simply be casted - but as the plot framework works with doubles there is no way to get around these rounding issues.

    By the way be aware of the fact that Qt5 and Qt4 differ internally how QDateTime stores the value. With Qt4 you run into overflows much earlier.

    Uwe

Similar Threads

  1. Replies: 3
    Last Post: 12th April 2013, 06:18
  2. Replies: 1
    Last Post: 23rd September 2012, 13:27
  3. How to calculate rendring time of Qpixmzp or graphicsview
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2011, 09:10
  4. Replies: 5
    Last Post: 19th November 2010, 02:25
  5. calculate draw time
    By johnsoga in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2009, 02:03

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
  •  
Qt is a trademark of The Qt Company.