fix: 收入支出分别画图
This commit is contained in:
parent
6efb61ce26
commit
8535a8dc29
1 changed files with 14 additions and 5 deletions
|
@ -11,11 +11,14 @@ class StatTab(TabPage):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.initUI()
|
self.initUI()
|
||||||
self.pg = parent.pg
|
self.pg = parent.pg
|
||||||
|
self.mode = 'out'
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
# 按钮
|
# 按钮
|
||||||
self.outButton = QPushButton('Expense')
|
self.outButton = QPushButton('Expense')
|
||||||
self.inButton = QPushButton('Income')
|
self.inButton = QPushButton('Income')
|
||||||
|
self.outButton.clicked.connect(self.onOutButtonClicked)
|
||||||
|
self.inButton.clicked.connect(self.onInButtonClicked)
|
||||||
buttonLayout = QHBoxLayout()
|
buttonLayout = QHBoxLayout()
|
||||||
buttonLayout.addWidget(self.outButton)
|
buttonLayout.addWidget(self.outButton)
|
||||||
buttonLayout.addWidget(self.inButton)
|
buttonLayout.addWidget(self.inButton)
|
||||||
|
@ -47,15 +50,19 @@ class StatTab(TabPage):
|
||||||
statLayout.addLayout(calenderLayout)
|
statLayout.addLayout(calenderLayout)
|
||||||
self.setLayout(statLayout)
|
self.setLayout(statLayout)
|
||||||
|
|
||||||
|
def onOutButtonClicked(self):
|
||||||
|
self.mode = 'out'
|
||||||
|
self.selected()
|
||||||
|
|
||||||
|
def onInButtonClicked(self):
|
||||||
|
self.mode = 'in'
|
||||||
|
self.selected()
|
||||||
|
|
||||||
def onCalendarClicked(self, date):
|
def onCalendarClicked(self, date):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def onCalendarPageChanged(self, year, month):
|
def onCalendarPageChanged(self, year, month):
|
||||||
print(year, month)
|
|
||||||
|
|
||||||
# 合计分类的交易量
|
# 合计分类的交易量
|
||||||
self.pg.execute("SELECT c_id, sum(amount)::numeric::float8 FROM transaction WHERE c_id IS NOT NULL and \
|
self.pg.execute("SELECT c_id, sum(amount)::numeric::float8 FROM transaction WHERE c_id IS NOT NULL and \
|
||||||
time BETWEEN %s AND %s GROUP BY c_id ORDER BY c_id", \
|
time BETWEEN %s AND %s GROUP BY c_id ORDER BY c_id", \
|
||||||
|
@ -64,7 +71,7 @@ class StatTab(TabPage):
|
||||||
print(self.statData)
|
print(self.statData)
|
||||||
|
|
||||||
# 获取此月所有交易类别
|
# 获取此月所有交易类别
|
||||||
self.pg.execute("SELECT c_id, meta->>'name' FROM category \
|
self.pg.execute("SELECT c_id, meta->>'type', meta->>'name' FROM category \
|
||||||
WHERE c_id in (SELECT c_id FROM transaction WHERE time between %s and %s GROUP BY c_id) \
|
WHERE c_id in (SELECT c_id FROM transaction WHERE time between %s and %s GROUP BY c_id) \
|
||||||
ORDER BY c_id", \
|
ORDER BY c_id", \
|
||||||
(datetime.date(year, month, 1), datetime.date(year, month+1, 1),))
|
(datetime.date(year, month, 1), datetime.date(year, month+1, 1),))
|
||||||
|
@ -74,8 +81,10 @@ class StatTab(TabPage):
|
||||||
# 填充饼状图
|
# 填充饼状图
|
||||||
self.chart.removeAllSeries()
|
self.chart.removeAllSeries()
|
||||||
series = QPieSeries()
|
series = QPieSeries()
|
||||||
|
|
||||||
for i in range(len(self.statData)):
|
for i in range(len(self.statData)):
|
||||||
series.append(self.categoryData[i][1], self.statData[i][1])
|
if (self.categoryData[i][1] == self.mode):
|
||||||
|
series.append(self.categoryData[i][2], self.statData[i][1])
|
||||||
self.chart.addSeries(series)
|
self.chart.addSeries(series)
|
||||||
|
|
||||||
def selected(self):
|
def selected(self):
|
||||||
|
|
Loading…
Reference in a new issue