I am trying to draw velocity-time graphics using qwtplot.
My X datas are QTime values and Y datas are corresponding speed values. I could not find any example on drawing plots with QTime. Can anyone simply explain how to draw QTime versus Y data ? If possible I would also like to learn how to scale QTime axis.
For future readers I have found a solution thanks to HeyyYO. I am sharing this very simple example :
#include "QApplication"
#include<qwt_plot_layout.h>
#include<qwt_plot_curve.h>
#include<qwt_scale_draw.h>
#include<qwt_scale_widget.h>
#include<qwt_legend.h>
class TimeScaleDraw:public QwtScaleDraw
{
public:
TimeScaleDraw(const QTime & base)
:baseTime(base)
{
}
virtual QwtText label(double v)const
{
QTime upTime = baseTime.addSecs((int)v);
return upTime.toString();
}
private:
QTime baseTime;
};
int main(int argc,char * argv[])
{
QApplication a(argc,argv);
QwtPlot * myPlot = new QwtPlot(NULL);
myPlot->setAxisScaleDraw(QwtPlot::xBottom,new TimeScaleDraw(QTime::currentTime()));
myPlot->setAxisTitle(QwtPlot::xBottom,"Time");
myPlot->setAxisLabelRotation(QwtPlot::xBottom,-50.0);
myPlot->setAxisLabelAlignment(QwtPlot::xBottom,Qt::AlignLeft|Qt::AlignBottom);
myPlot->setAxisTitle(QwtPlot::yLeft,"Speed");
QwtPlotCurve * cur = new QwtPlotCurve("Speed");
QwtPointSeriesData * data = new QwtPointSeriesData;
QVector<QPointF>* samples=new QVector<QPointF>;
for ( int i=0;i<60;i++)
{
samples->push_back(QPointF(i,i*i));
}
data->setSamples(*samples);
cur->setData(data);
cur->attach(myPlot);
myPlot->show();
return a.exec();
}