Qt曲线图模块QCustomPlot库介绍
QCustomPlot是一个小型的Qt画图标类,支持绘制静态曲线,动态曲线,多重坐标曲线,柱状图,蜡烛图等
前段时间用QChart模块画的图,一条曲线上面放8000条数据就会卡的不行必须要换个其他的控件,后来找到了曲线图模块QCustomplot库
这个库性能非常好,画曲线图折线图柱状图动态静态,放大缩小,都很好,用10 w条数据量无压力秒画出来一点也不卡
下载地址
https://www.qcustomplot.com/index.php/download引用>
里面分为
QCustomPlot 2和QCustomPlot 1我用的2这两个有一些函数的差异
下载解压以后我们只需要qcustomplot.h和qcustomplot.cpp
注意
箴文件里面写入QT +=printsupport
引用>动态效果
QCustomplot静态曲线图生成
//他继承QWidget所以构造里面放控件就会画到控件上 QCustomPlot * pCustomPlot=new QCustomPlot (ui→标签);//添加一条曲线 QCPGraph * pgraph=pCustomPlot→addGraph ();//给曲线准备数据设置数据 QVectorx (80000); QVector y (80000); for (int i=0;i 运行效果如下:
时间为坐标轴的静曲线图
大致差不多区别在于x轴改为时间
QCustomPlot * p2=new QCustomPlot (ui→label_2); QVector时间; QVector y;//模拟几个时间.toTime_t()是转换为时间戳从1970年到现在的秒数 time<& lt; QDateTime:: fromString (“2019-01-15 17:08:23”、“yyyy-MM-dd hh: mm: ss”) .toTime_t (); time<& lt; QDateTime:: fromString (“2019-01-25 17:08:23”、“yyyy-MM-dd hh: mm: ss”) .toTime_t (); time<& lt; QDateTime:: fromString (“2019-02-15 17:08:23”、“yyyy-MM-dd hh: mm: ss”) .toTime_t (); time<& lt; QDateTime:: fromString (“2019-02-25 17:08:23”、“yyyy-MM-dd hh: mm: ss”) .toTime_t (); time<& lt; QDateTime:: fromString (“2019-03-27 13:08:23”、“yyyy-MM-dd hh: mm: ss”) .toTime_t (); y<& lt; 5 & lt; & lt; 15 & lt; & lt; 5 & lt; & lt; 15 & lt; & lt; 5;//增加一条线 p2→addGraph ();//设置Y轴范围 p2→桠溪→setRange (0, 20);//QCPAxisTickerDateTime时间坐标轴必须要用智能指针 QSharedPointer 计时器(新QCPAxisTickerDateTime);//设置时间格式 计时器→setDateTimeFormat (“yyyy-MM-dd”);//设置时间轴一共几格//定时器→setTickCount (6);//设置标签旋转30°横着显示可能显示不全 p2→xAxis→setTickLabelRotation (30);//定时器→setTickStepStrategy (QCPAxisTicker:: tssMeetTickCount);//设置坐标轴 p2→xAxis→setTicker(计时器); 定出p2→xAxis→setRange((0),定出(4)); p2→图(0)→setData(时间,y); p2→调整(ui→label_2→宽度(),ui→label_2→高度()); p2→setInteractions (QCP:: iRangeDrag | QCP:: iRangeZoom); 运行效果如下:
QCustomplot动态曲线图生成
下图动态曲线是我用传感器采集的,大家可以用一些随机数据来测试
Qt图形图像开发之高性能曲线图模块QCustomplot库详细使用方法与实例(支持动、静曲线图)