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__()
|
||||
self.initUI()
|
||||
self.pg = parent.pg
|
||||
self.mode = 'out'
|
||||
|
||||
def initUI(self):
|
||||
# 按钮
|
||||
self.outButton = QPushButton('Expense')
|
||||
self.inButton = QPushButton('Income')
|
||||
self.outButton.clicked.connect(self.onOutButtonClicked)
|
||||
self.inButton.clicked.connect(self.onInButtonClicked)
|
||||
buttonLayout = QHBoxLayout()
|
||||
buttonLayout.addWidget(self.outButton)
|
||||
buttonLayout.addWidget(self.inButton)
|
||||
|
@ -47,15 +50,19 @@ class StatTab(TabPage):
|
|||
statLayout.addLayout(calenderLayout)
|
||||
self.setLayout(statLayout)
|
||||
|
||||
|
||||
def onOutButtonClicked(self):
|
||||
self.mode = 'out'
|
||||
self.selected()
|
||||
|
||||
def onInButtonClicked(self):
|
||||
self.mode = 'in'
|
||||
self.selected()
|
||||
|
||||
def onCalendarClicked(self, date):
|
||||
pass
|
||||
|
||||
|
||||
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 \
|
||||
time BETWEEN %s AND %s GROUP BY c_id ORDER BY c_id", \
|
||||
|
@ -64,7 +71,7 @@ class StatTab(TabPage):
|
|||
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) \
|
||||
ORDER BY c_id", \
|
||||
(datetime.date(year, month, 1), datetime.date(year, month+1, 1),))
|
||||
|
@ -74,8 +81,10 @@ class StatTab(TabPage):
|
|||
# 填充饼状图
|
||||
self.chart.removeAllSeries()
|
||||
series = QPieSeries()
|
||||
|
||||
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)
|
||||
|
||||
def selected(self):
|
||||
|
|
Loading…
Reference in a new issue