目录
一:实现思路
要使用PySide6的进行报表统计可以使用QtCharts模块进行账单统计,可以创建一个条形图或饼图来展示账单数据。我们讲介绍下如何使用条形图和饼状图来统计账单数据。
二:代码实现
1:饼状图
from PySide6.QtCharts import QChart, QChartView, QPieSeries, QPieSlice
from PySide6.QtGui import QPainter
from PySide6.QtWidgets import QApplication, QMainWindow
# 鼠标悬停在切片slice上时触发
def onHovered(the_slice: QPieSlice, state: bool):
the_slice.setExploded(state)
the_slice.setLabelVisible(state)
pure_label = the_slice.label().split(' ')[0]
if state:
the_slice.setLabel(f'{pure_label} {the_slice.value()} {the_slice.percentage():.0%}')
else:
the_slice.setLabel(pure_label)
app = QApplication([])
window =