Results 1 to 4 of 4

Thread: plotting a vector< pair<boost::date, double> >

  1. #1
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default plotting a vector< pair<boost::date, double> >

    Hi

    I have an exisiting vector< pair<boost::date, double> > where the boost::date are the x axis values, and the double the y axis values.
    I don't want to copy the existing data so I'm trying to point to it instead.

    There seem to be 3 derived classes of QwtData, and the one I hoped to use was QwtCPointerData. However, the ctor expects pointers to contiguous double arrays and stores the pointers only, not the data itself which is good.

    1. I wish to display the x axis labels as dates. Is the only way to use QwtTextLabel? boost::date can generate strings.

    2. Is it advised in this case to write a derived class of QwtData that would read behind the scenes inside the vector?

    regards,

  2. #2
    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: plotting a vector< pair<boost::date, double> >

    QwtData is the API that is used to link points to a curve. All derived classes of QwtData add an implementation how to store the values ( what doesn't mean that the values are always copied f.e. Qt containers support copy or write. ).

    But in your case you have to derive your own data object.

    Uwe

  3. #3
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: plotting a vector< pair<boost::date, double> >

    Yes I got it to work, thanks.
    Now, the x() function in QData returns a double.
    I have dates in the x axis.
    What is the process to plot dates (or generally custom types) on the x axis?

    rds,

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: plotting a vector< pair<boost::date, double> >

    Quote Originally Posted by hml View Post
    Yes I got it to work, thanks.
    Now, the x() function in QData returns a double.
    I have dates in the x axis.
    What is the process to plot dates (or generally custom types) on the x axis?

    rds,
    The simplest way: You need to derive a class from QwtScaleDraw and override the "QwtText label(double)" method to return the date string for the double the the axis engine wants to use for the axis.

    The right (hard) way: You need to derive a custom scale engine and scale draw for your data axis that computes tic positions for only the dates you want and also returns the properly formatted dates for those tic positions. Since QwtPlot does everything in real world double coordinates, you have to invent a mapping from dates to doubles and vice-versa, but you've already done that in your QwtData class.

    Uwe's way: (this space left blank for Uwe

    But I think one of the Qwt examples (CPU timer, maybe) already has an x-axis with a time stamp instead of numbers, so you can probably modify that code to suit your needs.

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.