3

qwtplot を使用して速度時間グラフィックスを描画しようとしています。

私のXデータはQTime値で、Yデータは対応する速度値です。QTime でプロットを描画する例は見つかりませんでした。QTime 対 Y データを描画する方法を簡単に説明できる人はいますか? 可能であれば、QTime 軸をスケーリングする方法も学びたいと思います。

4

1 に答える 1

5

将来の読者のために、私はHeyyYOのおかげで解決策を見つけました 。私はこの非常に単純な例を共有しています:

#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();
}
于 2015-11-11T15:08:07.620 に答える