forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PieChart.py
55 lines (46 loc) · 1.35 KB
/
PieChart.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019/10/2
@author: Irony
@site: https://pyqt5.com , https://github.com/892768447
@email: [email protected]
@file: PieChart
@description: 饼状图表
"""
from PyQt5.QtChart import QChartView, QChart, QPieSeries
from PyQt5.QtGui import QPainter, QColor
class Window(QChartView):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.resize(400, 300)
# 抗锯齿
self.setRenderHint(QPainter.Antialiasing)
# 图表
chart = QChart()
self.setChart(chart)
# 设置标题
chart.setTitle('Simple piechart example')
# 添加Series
chart.addSeries(self.getSeries())
def getSeries(self):
series = QPieSeries()
slice0 = series.append('10%', 1)
series.append('20%', 2)
series.append('70%', 7)
# 显示label文字
series.setLabelsVisible()
series.setPieSize(0.5)
# 使第一块突出显示
slice0.setLabelVisible()
slice0.setExploded()
# 设置第一块颜色
slice0.setColor(QColor(255, 0, 0, 100))
return series
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())