PDA

View Full Version : plotting a vector< pair<boost::date, double> >



hml
20th December 2009, 14:09
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,

Uwe
21st December 2009, 07:24
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

hml
21st December 2009, 09:07
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,

d_stranz
27th December 2009, 00:00
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.