我是靠谱客的博主 魁梧大门,最近开发中收集的这篇文章主要介绍Qcustomplot 时间轴显示曲线,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#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
#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 时间轴显示曲线所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部