Results 1 to 4 of 4

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

Threaded View

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

    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.

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.