gpt4 book ai didi

c++ - 在 QwtPlot 中使用 QTime 作为 X 轴

转载 作者:太空狗 更新时间:2023-10-29 20:37:49 24 4
gpt4 key购买 nike

我正在尝试使用 qwtplot 绘制速度-时间图形。

我的X数据是QTime值,Y数据是相应的速度值。我找不到任何关于用 QTime 绘图的例子。谁能简单解释一下如何绘制 QTime 与 Y 数据?如果可能的话,我还想学习如何缩放 QTime 轴。

最佳答案

感谢 HeyyYO,对于 future 的读者,我找到了解决方案.我正在分享这个非常简单的例子:

#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();
}

关于c++ - 在 QwtPlot 中使用 QTime 作为 X 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33635749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com