-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchartmanager.cpp
More file actions
47 lines (41 loc) · 1.1 KB
/
Copy pathchartmanager.cpp
File metadata and controls
47 lines (41 loc) · 1.1 KB
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
44
45
46
47
#include "chartmanager.h"
ChartManager::ChartManager(QChartView *view, QObject *parent)
: QObject(parent)
, timeCount(0)
{
line = new QLineSeries(this);
line->setName("温度");
chart = new QChart();
chart->addSeries(line);
chart->setTitle("实时温度曲线");
axisX = new QValueAxis(this);
axisY = new QValueAxis(this);
axisX->setRange(0,30);
axisY->setRange(0,60);
axisX->setTickCount(6);
axisY->setTickCount(7);
axisX->setTitleText("时间 /s");
axisY->setTitleText("温度 /℃");
chart->addAxis(axisX,Qt::AlignBottom);
chart->addAxis(axisY,Qt::AlignLeft);
line->attachAxis(axisX);
line->attachAxis(axisY);
view->setChart(chart);
view->setRenderHint(QPainter::Antialiasing);
}
//添加点
void ChartManager::addPoint(double temp)
{
line->append(timeCount,temp);
if(timeCount > 30){
axisX->setRange(timeCount-30,timeCount);
}
timeCount++;
}
//清零,回初始值
void ChartManager::clear()
{
line->clear();
timeCount = 0;
axisX->setRange(0,30);
}