当前位置:网站首页>QCustomPlot绘图工具常用方法
QCustomPlot绘图工具常用方法
2022-07-28 14:28:00 【飞天_】
添加一条曲线
QCPGraph* pGraph = pCustomPlot->addGraph();
设置数据
PCustomPlot->graph()->setData(x,y);
设置鼠标可以对图像放大缩小,拖拽
pCustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
重绘,每次更新数据需要重绘(或者设置多个数据之后一起进行重绘)
pCustomPlot->replot();
设置Y舟范围
pCustomPlot->yAxis->setRange(0,20);
设置X轴为时间轴
QCPAxisTickerDateTime //时间坐标轴必须要用智能指针
QSharedPointer<QCPAXisTickDateTime> timer(new QCPAxisTickerDateTime);
设置时间格式
timer->setDateTimeFormar("yyyy-MM-dd");
设置时间轴一共几格
timer->setTickCount(6);
设置X轴label旋转30度
pCustomPlot->xAxis->setTickLabelRotation(30);
设置坐标轴为时间格式
pCustomPlot->xAxis->setTicker(timer);
设置Y轴坐标自动缩放,能正常显示所有数据
pCustomPlot->yAxis->rescale(true);
设置曲线画笔
pCustomPlot->graph()->setPen(QPen(QColor(250,20,20)));
设置显示AxisTag(显示当前最新数据的提示)
AxisTag* pAxisTag = new AxisTag(pCustomPlot->graph()->valueAxis());
设置AxisTag的画笔
pAxisTag->setPen(pCustomPlot->graph()->pen());
设置AxisTag位置以及文本
pAxisTag->updatePositon(valuue); //value为当前AxisTag要显示的值
pAxisTag->setText(QString::number(value,'f',2)); //设置要显示的文本
移除QCustomPlot项
pCustomPlot->removeItem();
设置背景颜色
QBrush backRole;
backRole.setColor("skyblue");
backRole.setStyle(Qt::SolidPattern);
pCustomPlot->setBackground(backRole);
设置Legend背景透明
pCustomPlot->legend->setBrush(QColor(255,255,255,0));
QCPLayerable 可分层对象,所有可绘制到屏幕上的对象都是它的派生类
QCPAbstractItem 抽象类项,子类显示一些特殊的图形,比如图片QCPItemPixmap、文字QCPItemText、可加入箭头的直线QCPItemLine等等
QCPAbstractPlotable 可绘制的图抽象类,子类用来显示数据系列的图形,例如柱状图QCPBars、曲线QCPGraph、弧线QCPCurse、统计学箱QCPStatisticalBox
QCpLayoutElement 可布局元素
我们可将QCustomPlot 当做一个二维图表,一个绘图板的类,它继承自QWidget
设置图例位置
pCustomPlot->axisRect()->insetLayout()->setInsetAlignment(0,Qt::AlignLeft | QAlignTop);
pCustomPlot->legend->addElement(row,col,pCustomPlot->legend->item(1));
pCustomPlot->plotLayout->addElement(count,0,pCustomPlot->legend);
pCustomPlot->plotLayout->setRowStretchFactor(count,0.001);
设置X轴、Y轴颜色
pCustomPlot->xAxis->setBasePen(QColor(255,0,0));
pCcustomPlot->yAxis->setBasePen(QColor(255,0,0));
设置Tick颜色
pCustomPlot->xAxis->setTickPen(QColor(255,0,0));
pCustomPlot->yAxis->setSubTickPen(QPen(Qt::blue));
设置tick在坐标轴里面和外部的长度
pCustomPlot->xAxis->setTickLength(30,15); //里30px 外15px
设置坐标轴tick提示文字颜色
pCustomPlot->xAxis->setTickLabelColor(QColor(Qt::red));
设置X轴网格的颜色
pCustomPlot->xAxis->grid()->setPen(QPen(Qt::red));
设置坐标轴尾端箭头
pCustomPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
设置坐标轴上小刻度和箭头颜色(两个只能同时设置)
pCustomPlot->yAxis->setSubTickPen(QPen(Qt::red));
设置整个区域绘图颜色
pCustomPlot->setBackground(backRole);
设置坐标轴区域的颜色
pCustomPlot->axisRect()->setBackground(Qt::red);
边栏推荐
- 电压继电器DY-28C
- Requses template
- MySQL 8.0 common (continuous update)
- crmeb 标准版window+phpstudy8安装教程(二)
- Introduction to grpc
- crmeb 标准版window+phpstudy8安装教程(三)
- Opencv - closely combine multiple irregular small graphs into large graphs
- Classic Dijkstra and the longest way
- 配置cx-oracle 解决(cx_Oracle.DatabaseError) DPI-1047: Cannot locate a 64-bit Oracle Client library: “Th
- Cross domain problems in the configuration of.Net core version 3.1
猜你喜欢
随机推荐
Here comes the full open source free customer service system
Execution process of SQL statement
2022-07-28日报:Science:AI设计蛋白质再获突破,可设计特定功能性蛋白质
For loop
分享一下一二线大厂HR面经分享
CANoe使用教程
Configure CX Oracle solution (cx_oracle.databaseerror) dpi-1047: cannot locate a 64 bit Oracle client library: "th
3559. Ring counting
crmeb标准版附带的客服系统
Publish raspberry pie web page with cpolar (release of apache2 web page)
Principle and configuration of MPLS LDP
Crmeb v4.3 deployment process
PMP [agile textbook + full truth simulation question]. After the exam on June 25, agile has become the top priority
代码比较干净的多商户商城系统
软件测试的流程规范有哪些?具体要怎么做?
7/13 (pond sampling)
3540. Binary search tree
DataTables warning: table id=campaigntable - cannot reinitialize datatable. solve
day 7/12
7、实时数据备份和实时时钟相关定义








