我是靠谱客的博主 魁梧大门,这篇文章主要介绍Qcustomplot 时间轴显示曲线,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef LOADPLOT_H #define LOADPLOT_H #include "liftcommon_global.h" #include <QWidget> #include "qcustomplot.h" class LIFTCOMMONSHARED_EXPORT LoadPlot : public QCustomPlot { Q_OBJECT public: explicit LoadPlot(QWidget *parent = nullptr); void setLineValue(double yValue); void addData(double key, double value); private: QCPGraph *m_graph; QCPGraph *m_graphLimit; QCPItemStraightLine *m_line; QVector<double> m_keyvec; QVector<double> m_valuevec; }; #endif // LOADPLOT_H
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "loadplot.h" LoadPlot::LoadPlot(QWidget *parent) : QCustomPlot(parent) { setBackground(QBrush(QColor(53, 54, 57))); legend->setVisible(true); legend->setFont(QFont("Helvetica",8)); legend->setBrush(QColor(255,255,255,0)); legend->setTextColor(QColor(225,255,18)); legend->setBorderPen(Qt::NoPen); m_line = new QCPItemStraightLine(this); m_line->setPen(QPen(Qt::red)); m_line->setLayer("overlay"); m_line->setClipToAxisRect(true); m_line->point1->setTypeX(QCPItemPosition::ptAbsolute); m_line->point2->setTypeY(QCPItemPosition::ptPlotCoords); m_line->point1->setCoords(xAxis->range().lower,0); m_line->point2->setCoords(xAxis->range().upper,0); QPen axis(QColor(98,112,128,220),0.5,Qt::DotLine); this->xAxis->grid()->setPen(axis); this->yAxis->grid()->setPen(axis); QFont font; font.setPixelSize(11); this->xAxis->grid()->setZeroLinePen(Qt::NoPen); this->xAxis->setTickLabelFont(font); this->xAxis->setLabelColor(QColor(217, 255, 253)); this->xAxis->setBasePen(QPen(QColor(230,230,230,230),0.8)); this->xAxis->setTickLabelColor(QColor(217, 255, 253)); this->xAxis->setTickPen(QColor(217, 255, 253)); this->xAxis->setSubTicks(false); this->yAxis->grid()->setZeroLinePen(Qt::NoPen); this->yAxis->setTickLabelFont(font); this->yAxis->setLabelColor(QColor(217, 255, 253)); this->yAxis->setBasePen(QPen(QColor(230,230,230,230),0.8)); this->yAxis->setTickLabelColor(QColor(217, 255, 253)); this->yAxis->setTickPen(QColor(217, 255, 253)); this->yAxis->setSubTicks(false); QSharedPointer<QCPAxisTickerDateTime> dateTick(new QCPAxisTickerDateTime); dateTick->setTickCount(8); dateTick->setDateTimeFormat("mm:ss"); xAxis->setTicker(dateTick); m_graph = addGraph(); m_graph->setName("吊重"); m_graph->setPen(QPen(QColor(26, 245, 26))); m_graph->setBrush(QBrush(QColor(26, 245, 26,150))); m_graphLimit = addGraph(); m_graphLimit->setName("预警门限"); m_graphLimit->setPen(QPen(QColor(255, 0, 0))); replot(); } void LoadPlot::setLineValue(double yValue) { m_line->point1->setCoords(xAxis->range().lower, yValue); m_line->point2->setCoords(xAxis->range().upper, yValue); replot(); } void LoadPlot::addData(double key, double value) { while (m_keyvec.count()>=8) { m_keyvec.pop_front(); m_valuevec.pop_front(); } m_keyvec.append(key); m_valuevec.append(value); xAxis->setRange(m_keyvec.front(),m_keyvec.back());//设定x轴的范围 yAxis->rescale(true); m_graph->setData(m_keyvec,m_valuevec); replot(); }

最后

以上就是魁梧大门最近收集整理的关于Qcustomplot 时间轴显示曲线的全部内容,更多相关Qcustomplot内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部