PDA

View Full Version : Time/Date Axis



sigger
27th June 2008, 17:48
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

Uwe
27th June 2008, 19:29
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

dinojerm
30th July 2008, 20:52
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):

class StockTimeScaleDraw: public QwtScaleDraw
{
public:
StockTimeScaleDraw(QString fmt) : format(fmt) { }

virtual QwtText label(double v) const
{
QDateTime t = QDateTime::fromTime_t((int)v);
return t.toString(format);
}
private:
const QString format;
}

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.

philwinder
14th March 2009, 23:58
Thanks for the code post. Here is an much more simple example of a plot using a QDateTime base.

drizzt
13th November 2009, 08:48
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

Lupus
20th July 2010, 13:36
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.

techr
29th November 2010, 21:18
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

Patrik
1st December 2010, 12:27
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());

FelixB
1st December 2010, 14:08
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?

falconium
28th April 2011, 22:08
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... :(

corrado1972
29th April 2011, 11:12
please download latest Qwt (6.0) and recompile: it should works.

TorAn
30th April 2011, 17:04
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

corrado1972
1st May 2011, 10:55
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