我是靠谱客的博主 落寞宝马,这篇文章主要介绍QT之QCustomPlot的使用(二)--实时曲线,现在分享给大家,希望可以做个参考。

首先,我们先进行的是以时间为依据来进行动态展示,下面的代码是完整的可以进行使用;

复制代码
1
2
3
4
5
6
7
8
9
10
//动态显示的功能 for (int i = 0; i < 10; i++) { num[i] = 0; } n = 0; QTimer *timer = new QTimer; timer->start(500); connect(timer, SIGNAL(timeout()), this, SLOT(Graph_Show()));
复制代码
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
void Graph_Show() { QTime t; t = QTime::currentTime(); qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); n = qrand() % 50; for (int i = 0; i < 9; i++) { num[i] = num[i + 1]; } num[9] = n; for (int i = 0; i < 10; i++) { temp[i] = i; temp1[i] = num[i]; } m_pCustomPlot = new QCustomPlot(this);//初始化曲线图 m_pCustomPlot->setGeometry(1, 1, 400, 300);//初始化曲线图坐标 m_pCustomPlot->setLocale(QLocale(QLocale::Chinese, QLocale::China)); m_pCustomPlot->addGraph(); m_pCustomPlot->graph(0)->setLineStyle(QCPGraph::lsLine); m_pCustomPlot->graph(0)->setPen(QPen(QColor(0, 0, 255, 200))); m_pCustomPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5)); m_pCustomPlot->graph(0)->setData(temp, temp1); m_pCustomPlot->addGraph(); m_pCustomPlot->graph(1)->setPen(QPen(Qt::red)); m_pCustomPlot->graph(1)->setLineStyle(QCPGraph::lsNone); m_pCustomPlot->graph(1)->setScatterStyle(QCPScatterStyle::ssDisc); m_pCustomPlot->graph(1)->setData(temp, temp1); m_pCustomPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8)); m_pCustomPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8)); m_pCustomPlot->xAxis->setLabel(“v”); m_pCustomPlot->yAxis->setLabel(“mV”); m_pCustomPlot->xAxis->setRange(0, 10); m_pCustomPlot->yAxis->setRange(-50, 50); m_pCustomPlot->xAxis2->setVisible(false); m_pCustomPlot->yAxis2->setVisible(false); m_pCustomPlot->xAxis2->setTicks(false); m_pCustomPlot->yAxis2->setTicks(false); m_pCustomPlot->xAxis2->setTickLabels(false); m_pCustomPlot->yAxis2->setTickLabels(false); m_pCustomPlot->replot(); }

最后

以上就是落寞宝马最近收集整理的关于QT之QCustomPlot的使用(二)--实时曲线的全部内容,更多相关QT之QCustomPlot内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部