qcustomplot添加图例_qchart显示点数据

qcustomplot添加图例_qchart显示点数据【实例简介】QCustomPlot动态绘图,解决CPU占用内存高问题【实例截图】Qt动态实时绘图【核心代码】LXTracer::LXTracer(QCustomPlot*_plot,TracerType_type,QObject*parent):QObject(parent),m_plot(_plot),m_type(_type){m_visible=true;m_tracer=…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

【实例简介】QCustomPlot动态绘图,解决CPU占用内存高问题

【实例截图】Qt动态实时绘图

91b8a2c89eca3d03cb2020ec029df597.png

【核心代码】

LXTracer::LXTracer(QCustomPlot *_plot, TracerType _type, QObject *parent)

: QObject(parent),

m_plot(_plot),

m_type(_type)

{

m_visible = true;

m_tracer = Q_NULLPTR;// 跟踪的点

m_label = Q_NULLPTR;// 显示的数值

m_arrow = Q_NULLPTR;// 箭头

if (m_plot)

{

QColor clrDefault(Qt::red);

QBrush brushDefault(Qt::NoBrush);

QPen penDefault(clrDefault);

// penDefault.setBrush(brushDefault);

penDefault.setWidthF(0.5);

m_tracer = new QCPItemTracer(m_plot);

m_tracer->setStyle(QCPItemTracer::tsCircle);

m_tracer->setPen(penDefault);

m_tracer->setBrush(brushDefault);

m_label = new QCPItemText(m_plot);

m_label->setLayer(“overlay”);

m_label->setClipToAxisRect(false);

m_label->setPadding(QMargins(5, 5, 5, 5));

m_label->setBrush(brushDefault);

m_label->setPen(penDefault);

m_label->position->setParentAnchor(m_tracer->position);

// m_label->setFont(QFont(“宋体”, 8));

m_label->setFont(QFont(“Arial”, 8));

m_label->setColor(clrDefault);

m_label->setText(“”);

m_arrow = new QCPItemLine(m_plot);

QPen arrowPen(clrDefault, 1);

m_arrow->setPen(penDefault);

m_arrow->setLayer(“overlay”);

m_arrow->setClipToAxisRect(false);

m_arrow->setHead(QCPLineEnding::esSpikeArrow);//设置头部为箭头形状

switch (m_type)

{

case XAxisTracer:

{

m_tracer->position->setTypeX(QCPItemPosition::ptPlotCoords);

m_tracer->position->setTypeY(QCPItemPosition::ptAxisRectRatio);

m_tracer->setSize(7);

m_label->setPositionAlignment(Qt::AlignTop | Qt::AlignHCenter);

m_arrow->end->setParentAnchor(m_tracer->position);

m_arrow->start->setParentAnchor(m_arrow->end);

m_arrow->start->setCoords(0, 20);//偏移量

break;

}

case YAxisTracer:

{

m_tracer->position->setTypeX(QCPItemPosition::ptAxisRectRatio);

m_tracer->position->setTypeY(QCPItemPosition::ptPlotCoords);

m_tracer->setSize(7);

m_label->setPositionAlignment(Qt::AlignRight | Qt::AlignHCenter);

m_arrow->end->setParentAnchor(m_tracer->position);

m_arrow->start->setParentAnchor(m_label->position);

m_arrow->start->setCoords(-20, 0);//偏移量

break;

}

case DataTracer:

{

m_tracer->position->setTypeX(QCPItemPosition::ptPlotCoords);

m_tracer->position->setTypeY(QCPItemPosition::ptPlotCoords);

m_tracer->setSize(5);

m_label->setPositionAlignment(Qt::AlignLeft | Qt::AlignVCenter);

m_arrow->end->setParentAnchor(m_tracer->position);

m_arrow->start->setParentAnchor(m_arrow->end);

m_arrow->start->setCoords(20, 0);

break;

}

default:

break;

}

setVisible(false);

}

}

LXTracer::~LXTracer()

{

if(m_plot)

{

if (m_tracer)

{

m_plot->removeItem(m_tracer);

}

if (m_label)

{

m_plot->removeItem(m_label);

}

if (m_arrow)

{

m_plot->removeItem(m_arrow);

}

}

}

void LXTracer::setPen(const QPen &pen)

{

if(m_tracer)

{

m_tracer->setPen(pen);

}

if(m_arrow)

{

m_arrow->setPen(pen);

}

}

void LXTracer::setBrush(const QBrush &brush)

{

if(m_tracer)

{

m_tracer->setBrush(brush);

}

}

void LXTracer::setLabelPen(const QPen &pen)

{

if(m_label)

{

m_label->setPen(pen);

m_label->setBrush(Qt::NoBrush);

m_label->setColor(pen.color());

}

}

void LXTracer::setText(const QString &text)

{

if(m_label)

{

m_label->setText(text);

}

}

void LXTracer::setVisible(bool vis)

{

m_visible = vis;

if(m_tracer)

{

m_tracer->setVisible(m_visible);

}

if(m_label)

{

m_label->setVisible(m_visible);

}

if(m_arrow)

{

m_arrow->setVisible(m_visible);

}

}

void LXTracer::updatePosition(double xValue, double yValue)

{

if (!m_visible)

{

setVisible(true);

m_visible = true;

}

if (yValue > m_plot->yAxis->range().upper)

{

yValue = m_plot->yAxis->range().upper;

}

switch (m_type)

{

case XAxisTracer:

{

m_tracer->position->setCoords(xValue, 1);

m_label->position->setCoords(0, 15);

m_arrow->start->setCoords(0, 15);

m_arrow->end->setCoords(0, 0);

setText(QString::number(xValue));

break;

}

case YAxisTracer:

{

m_tracer->position->setCoords(0, yValue);

m_label->position->setCoords(-20, 0);

// m_arrow->start->setCoords(20, 0);

// m_arrow->end->setCoords(0, 0);

setText(QString::number(yValue));

break;

}

case DataTracer:

{

m_tracer->position->setCoords(xValue, yValue);

m_label->position->setCoords(20, 0);

setText(QString(“x:%1,y:%2”).arg(xValue).arg(yValue));

break;

}

default:

break;

}

}

LXTraceLine::LXTraceLine(QCustomPlot *_plot, LineType _type, QObject *parent)

: QObject(parent),

m_type(_type),

m_plot(_plot)

{

m_lineV = Q_NULLPTR;

m_lineH = Q_NULLPTR;

initLine();

}

LXTraceLine::~LXTraceLine()

{

if(m_plot)

{

if (m_lineV)

{

m_plot->removeItem(m_lineV);

}

if (m_lineH)

{

m_plot->removeItem(m_lineH);

}

}

}

void LXTraceLine::initLine()

{

if(m_plot)

{

QPen linesPen(Qt::red, 1, Qt::SolidLine);

if(VerticalLine == m_type || Both == m_type)

{

m_lineV = new QCPItemStraightLine(m_plot);//垂直线

m_lineV->setLayer(“overlay”);

m_lineV->setPen(linesPen);

m_lineV->setClipToAxisRect(true);

m_lineV->point1->setCoords(0, 0);

m_lineV->point2->setCoords(0, 0);

}

if(HorizonLine == m_type || Both == m_type)

{

m_lineH = new QCPItemStraightLine(m_plot);//水平线

m_lineH->setLayer(“overlay”);

m_lineH->setPen(linesPen);

m_lineH->setClipToAxisRect(true);

m_lineH->point1->setCoords(0, 0);

m_lineH->point2->setCoords(0, 0);

}

}

}

void LXTraceLine::updatePosition(double xValue, double yValue)

{

if(VerticalLine == m_type || Both == m_type)

{

if(m_lineV)

{

m_lineV->point1->setCoords(xValue, m_plot->yAxis->range().lower);

m_lineV->point2->setCoords(xValue, m_plot->yAxis->range().upper);

}

}

if(HorizonLine == m_type || Both == m_type)

{

if(m_lineH)

{

m_lineH->point1->setCoords(m_plot->xAxis->range().lower, yValue);

m_lineH->point2->setCoords(m_plot->xAxis->range().upper, yValue);

}

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/184185.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 集锦——浏览器每次访问自动更新网页,不用手工设置,附Google/firefox/Ie

    在做开发web开发的时候,经常要使用到浏览器来着进行调试,那么有时候自己修改了内容,可是在浏览器上还是没有显示出来,费了好久才发现是浏览器缓存的问题。还要强制刷新缓存 就是 Ctrl + F5。所以在开发时候,最好将自己的调试浏览器设置为访问自动刷新网页,不要使用页面的缓存。下面就是常用开发浏览器的设置:1. Chrome 浏览器打开到开发者模式:将Disable cache

    2022年2月24日
    265
  • kill命令杀死所有进程_linux 杀死进程

    kill命令杀死所有进程_linux 杀死进程1kill:根据进程号(PID)杀死进程在linux上,一般常用的杀死进程的命令是kill,但是也有缺陷,下面说1、查看指定名称的进程,如下我查看运行python程序的进程pythonaux|greppython2、根据进程号(PID)杀死进程:第二列显示的就是进程号killPID3、强制杀死进程,有些进程可能杀不死,就加个-9参数,强制让它死掉!kill-9PID5、杀死多个进程,在后面跟多个进程的PID号即可kill-9PID1PID2PID3…

    2025年7月10日
    3
  • 如何求原根_求模47的所有原根

    如何求原根_求模47的所有原根说这种最好就是举个例子比如说求81的所有原根 先说欧拉函数通式:通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1,p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数(小于等于1)就是1本身)。(注意:每种质因数只一个。比如12=2*2*3那么φ(12)=12*(1-1/2)*(1-1/…

    2025年7月5日
    2
  • atm异步传输模式特性_ATM是什么模式

    atm异步传输模式特性_ATM是什么模式AsynchronousTransferMode.  ATM是一种传输模式,在这一模式中,信息被组织成信元,因包含来自某用户信息的各个信元不需要周期性出现,这种传输模式是异步的。   ATM是网络新技术,它采用基于信元的异步传输模式和虚电路结构,根本上解决了多媒体的实时性及带宽问题。实现面向虚链路的点到点传输,它通常提供155Mbps的带宽。它既汲取了话务通讯中电路交换的“有连接”服务

    2022年9月21日
    3
  • php7使用curl扩展「建议收藏」

    php7使用curl扩展「建议收藏」  前言:最近项目中要调用一些接口,看到网上很多都使用curl,但由于刚开始,php很多的语法都不是很熟悉,例如如何调用第三方函数等,为了使用curl_init()等函数,从安装php的扩展curl开始踩了很多坑,对于环境安装真的是比较头疼的事情,往往可能因为一些小问题而不成功,而且按照网上乱七八糟的博客说的做,真的一点用都没有,特此记录一下,希望以后的编程生涯中尽量少犯这种错误。首先给出环境…

    2022年10月21日
    1
  • 常量池和堆的区别_字符串常量池在堆中还是方法区

    常量池和堆的区别_字符串常量池在堆中还是方法区写在前面:博主是一位普普通通的19届二本大学生,平时最大的爱好就是听听歌,逛逛B站。博主很喜欢的一句话花开堪折直须折,莫待无花空折枝:博主的理解是头一次为人,就应该做自己想做的事,做自己不后悔的事,做自己以后不会留有遗憾的事,做自己觉得有意义的事,不浪费这大好的青春年华。博主写博客目的是记录所学到的知识并方便自己复习,在记录知识的同时获得部分浏览量,得到更多人的认可,满足小小的成就感,同时在写博客的途中结交更多志同道合的朋友,让自己在技术的路上并不孤单。目录:1.常量池与Class常量池2.运.

    2022年7月28日
    11

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号