Results 1 to 13 of 13

Thread: Time/Date Axis

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

    Default Time/Date Axis

    I've seen some old references to interest in a Time/Date axis. Has anyone done this yet, even in an alpha or beta stage? If not, we're interested in implementing this.

    Specifically, we're looking to be able to specify the format of the numbers on the major tick of the axis. I believe that is (part of) the purpose of the QwtScaleEngine; please correct me if I am wrong.

    I would like to tell the scale engine what format the major tick should appear in. For example, either "hh:mm:ss" or "hh:mm" or "mm/dd".

    Being new to Qwt, I would love some guidance on what I need to subclass (if not just QwtScaleEngine) or otherwise do to implement this.

    By the way, this being done in conjunction with an effort to implement a stock or securities charting QwtPlotItem to show OHLC bars (Open, High, Low, Close).

    Many thanks.

    - sigger

  2. The following user says thank you to sigger for this useful post:

    DadaLee (31st July 2008)

  3. #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: Time/Date Axis

    I've seen some old references to interest in a Time/Date axis. Has anyone done this yet, even in an alpha or beta stage? If not, we're interested in implementing this.
    A QwtDateTimeScaleEngine is on my TODO list, but nothing has been done yet. Your contribution is very welcome.
    By the way, this being done in conjunction with an effort to implement a stock or securities charting QwtPlotItem to show OHLC bars (Open, High, Low, Close).
    Qwt 5.2 is planned to include new type of curves and other plot items ( a couple of them are already implemented). Therefore the implementation of QwtPlotCurve had been reorganized, so that you can implement curves with other types of data/symbols more easily. So I recommend to start with the code from the SVN trunk instead of Qwt 5.1 - if you can.

    Contact me by mail if you need further support,

    Uwe

  4. #3
    Join Date
    Jul 2008
    Posts
    1
    Thanked 5 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Time/Date Axis

    I wrote code for this stuff, based on the provided Qwt examples.
    For the time/date axis, the following simple class was used (it assumes the time is stored in the time_t form):
    Qt Code:
    1. class StockTimeScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. StockTimeScaleDraw(QString fmt) : format(fmt) { }
    5.  
    6. virtual QwtText label(double v) const
    7. {
    8. QDateTime t = QDateTime::fromTime_t((int)v);
    9. return t.toString(format);
    10. }
    11. private:
    12. const QString format;
    13. }
    To copy to clipboard, switch view to plain text mode 

    The attached program contains a plot item to draw candlesticks based on OHLC data. This example generates random data each second, aggregating and creating bars every 10 seconds. Another feature that might be useful is the ability to adjust the scale by clicking and dragging the axes.
    Hopefully some of this will be helpful to others.
    Attached Files Attached Files

  5. The following 5 users say thank you to dinojerm for this useful post:

    joro (19th March 2009), philwinder (14th March 2009), praseodym (27th November 2010), skater (13th March 2012), uppu (18th November 2009)

  6. #4
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Time/Date Axis

    Thanks for the code post. Here is an much more simple example of a plot using a QDateTime base.
    Attached Files Attached Files
    Best Regards,
    Phil Winder
    www.philwinder.com

  7. The following 5 users say thank you to philwinder for this useful post:

    Carlton (28th March 2009), fra74 (13th April 2009), frankiefrank (3rd January 2011), praseodym (27th November 2010), uppu (18th November 2009)

  8. #5
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Time/Date Axis

    i want to have a timescale with millisecond accuracy, but i don't really know how to do that.
    All examples only have second accuracy and always use QDateTime::fromTime_t(int v) or something else.

    Has somebody experiences with that and can give me a tip how to solve that problem?

    thx

  9. #6
    Join Date
    May 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Time/Date Axis

    Hej drizzt.
    My idea would be to create a similar type to time_t where you count milliseconds from some start date.
    The easiest thing would be to use QDateTime::toTime_t of your start date and multiply it to get your milliseconds and add as many milliseconds as needed for the datapoint
    Then you could call

    QDateTime t = QDateTime::addMSecs((qint64)v);
    return t.toString("yyyy-MM-dd HH:mm:ss:zzz");

    in the label function from dinojerm.

    Just take care of the really big number which is lager than an interger, so use qint64.
    I have NOT tested this, it ist just a suggestion.

  10. #7
    Join Date
    Aug 2009
    Location
    The Netherlands
    Posts
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Time/Date Axis

    Hi Phil Winder,
    is it possible to get the datetime.zip? looks like the above link does not contain all the files...after i download, i could not unzip it...

    Thanks in advance

  11. #8
    Join Date
    Nov 2010
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Time/Date Axis

    I'm very interested in something similar to this. Basically I need only dates as X axis. Do you thing this snippet is correct?

    QwtPlot *plt = ui->qwtPlot;
    plt->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw("dd/M/yy"));
    QDate date = getDateFromSomewhere();
    QDateTime tm(date);
    xData.append(tm.toTime_t());
    yData.append(someData());

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

    Default Re: Time/Date Axis

    Quote Originally Posted by Patrik View Post
    I'm very interested in something similar to this. Basically I need only dates as X axis. Do you thing this snippet is correct?
    why don't you try it by yourself?

  13. #10
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Time/Date Axis

    Hi Philminder, I tried your example under 6.00-rc5, and it fails at:

    ..\datetime\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
    ..\datetime\mainwindow.cpp:40: error: no matching function for call to 'QwtPlotCurve::setData(double*, double*, int)'
    ..\libraries\qwt/qwt_plot_seriesitem.h:146: note: candidates are: void QwtPlotSeriesItem<T>::setData(QwtSeriesData<T>*) [with T = QPointF]

    It looks like setData arguments have changed...

  14. #11
    Join Date
    Jul 2010
    Posts
    37
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Time/Date Axis

    please download latest Qwt (6.0) and recompile: it should works.

  15. #12
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Time/Date Axis

    corrado1972 -
    I downloaded datetime.zip and curve->setData(&xData[0], &yData[0], xData.size()); (mainwindow.cpp line40) does not compile with Qwt 6.0.0.

    setData should be replaced with setRawSamples
    Last edited by TorAn; 30th April 2011 at 16:09.

  16. #13
    Join Date
    Jul 2010
    Posts
    37
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Time/Date Axis

    TorAn excuse me but I understood that the problem was referred to the examples included in Qwt release.
    My advice is to discard the datetime.zip and look in the examples, friedberg and cpuplot: there is all the necessary to get datetime axis.
    bye

Similar Threads

  1. Relocating axis labels
    By malcom2073 in forum Qwt
    Replies: 0
    Last Post: 9th May 2008, 13:01
  2. Set axis title on the right side
    By pospiech in forum Qwt
    Replies: 1
    Last Post: 14th March 2008, 07:26
  3. Qwt and custom axis
    By jiveaxe in forum Qwt
    Replies: 3
    Last Post: 14th November 2007, 15:50
  4. Qwt - extra axis
    By steg90 in forum Qwt
    Replies: 2
    Last Post: 10th July 2007, 14:41

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.