-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartManager.cpp
More file actions
56 lines (48 loc) · 1.58 KB
/
Copy pathChartManager.cpp
File metadata and controls
56 lines (48 loc) · 1.58 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
48
49
50
51
52
53
54
55
56
// ChartManager.cpp
#include "ChartManager.h"
ChartManager::ChartManager(QObject *parent) : QObject(parent) {
// Initialization if needed
}
void ChartManager::setupCpuChart(QChart *chart) {
// Create chart
QChart *chart = new QChart();
chart->setTitle("CPU Usage");
// Configure axis
QtCharts::QValueAxis *yAxis = new QtCharts::QValueAxis;
yAxis->setRange(0, 100);
yAxis->setTitleText("Usage (%)");
QtCharts::QValueAxis *xAxis = new QtCharts::QValueAxis;
xAxis->setRange(0, 60);
xAxis->setTitleText("Seconds");
chart->addAxis(xAxis, Qt::AlignBottom);
chart->addAxis(yAxis, Qt::AlignLeft);
//QLineSeries *series = new QLineSeries();
//chart->addSeries(series);
cpuChartView = new QChartView(chart);
cpuChartView->setRenderHint(QPainter::Antialiasing);
// Parse CPU Usage and update graph every second
int sec_counter = 0;
double specific_usage = 0;
cpuSeries = new QLineSeries();
chart->addSeries(cpuSeries);
cpuSeries->attachAxis(yAxis);
cpuSeries->attachAxis(xAxis);
while(1) {
sleep(1);
char *total_usage = get_cpu_usage();
char *temp = total_usage;
sscanf(total_usage, "%lf", &specific_usage);
//while(sscanf(temp, "%lf", &specific_usage) == 1) {
if (sec_counter > 60) {
sec_counter %= 60;
}
cpuSeries->append(sec_counter, specific_usage);
temp = strchr(temp, ',');
if (temp == NULL) {
break;
}
temp++;
//}
sec_counter++;
}
}