-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphwindow.cpp
145 lines (116 loc) · 3.9 KB
/
graphwindow.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "graphwindow.h"
#include "ui_graphwindow.h"
graphWindow::graphWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::graphWindow)
{
ui->setupUi(this);
this->setWindowTitle("Data over time");
connect(ui->draw,SIGNAL(clicked()),this,SLOT(reLoadGraph()));
}
graphWindow::~graphWindow()
{
delete ui;
}
void graphWindow::loadData(StartEnd se)
{
allDataStartDay=new QDateTime(se.startDate,se.startTime);
allDataEndDay=new QDateTime(se.endDate,se.endTime);
int dayTimeSpan=allDataEndDay->date().day()-allDataStartDay->date().day()+1;
ui->endTime->setMaximumDateTime(*allDataEndDay);
ui->startTime->setMinimumDateTime(*allDataStartDay);
ui->startTime->setDateTime(*allDataStartDay);
ui->endTime->setDateTime(*allDataEndDay);
startOrderNumber.resize(dayTimeSpan*24+5);
endOrderNumber.resize(dayTimeSpan*24+5);
feesrNumber.resize(dayTimeSpan*24+5);
}
void graphWindow::addData(QString orderID,QDateTime oneRecordStartDateTime,QDateTime oneRecordEndDateTime,int startGrid,int endGrid,double fees)
{
int startHourID= computeHourID(oneRecordStartDateTime);
int endHourID=computeHourID(oneRecordEndDateTime);
if(startHourID>=startOrderNumber.size())
{
return;
}
if(endHourID>=endOrderNumber.size())
{
return;
}
startOrderNumber[startHourID]++;
feesrNumber[startHourID]+=fees;
endOrderNumber[endHourID]++;
}
void graphWindow::loadGraph()
{
startLine=new QLineSeries(this);
feesLine=new QLineSeries(this);
chart=new QChart();
for(int i=0;i<startOrderNumber.size()-5;i++)
{
startLine->append(i,startOrderNumber[i]);
feesLine->append(i,feesrNumber[i]);
}
for(int i=0;i<endOrderNumber.size()-5;i++)
{
endLine->append(i,endOrderNumber[i]);
}
startLine->setName("Number of departure orders over time");
// endLine->setName("Number of departure orders over time");
feesLine->setName("Total fees of departure orders over time");
chart->addSeries(startLine);
// chart->addSeries(endLine);
chart->addSeries(feesLine);
QValueAxis *axisX = new QValueAxis;
QValueAxis *axisY = new QValueAxis;
axisX->setRange(0, startOrderNumber.size());
axisX->setTitleText("time(h)");
axisX->setLabelFormat("%d");
axisY->setRange(0,3000);
chart->addAxis(axisX, Qt::AlignBottom);
chart->addAxis(axisY, Qt::AlignLeft);
this->show();
ui->chartView->setChart(chart);
ui->chartView->show();
}
int graphWindow::computeHourID(QDateTime dateTime)
{
int hourID=allDataStartDay->secsTo(dateTime)/3600;
return hourID;
}
void graphWindow::reLoadGraph()
{
QDateTime startDraw=ui->startTime->dateTime();
QDateTime endDraw=ui->endTime->dateTime();
startLine=new QLineSeries(this);
feesLine=new QLineSeries(this);
chart=new QChart();
int startHourID=computeHourID(startDraw);
int endHourID=computeHourID(endDraw);
for(int i=startHourID;i<=endHourID;i++)
{
startLine->append(i,startOrderNumber[i]);
feesLine->append(i,feesrNumber[i]);
}
for(int i=startHourID;i<endHourID;i++)
{
endLine->append(i,endOrderNumber[i]);
}
startLine->setName("Number of Departure orders over time");
// endLine->setName("Number of Arrival orders over time");
feesLine->setName("Total fees of departure orders over time");
chart->addSeries(startLine);
// chart->addSeries(endLine);
chart->addSeries(feesLine);
QValueAxis *axisX = new QValueAxis;
QValueAxis *axisY = new QValueAxis;
axisX->setRange(0, startOrderNumber.size());//设置坐标轴范围
axisX->setTitleText("time(h)");//标题
axisX->setLabelFormat("%d"); //标签格式:每个单位保留1位小数
axisY->setRange(0,1000);
chart->addAxis(axisX, Qt::AlignBottom);
chart->addAxis(axisY, Qt::AlignLeft);
this->show();
ui->chartView->setChart(chart);
ui->chartView->show();
}