| 29 | class Window(QChartView): |
| 30 | |
| 31 | def __init__(self, *args, **kwargs): |
| 32 | super(Window, self).__init__(*args, **kwargs) |
| 33 | self.resize(400, 300) |
| 34 | # 抗锯齿 |
| 35 | self.setRenderHint(QPainter.Antialiasing) |
| 36 | |
| 37 | # 图表 |
| 38 | chart = QChart() |
| 39 | self.setChart(chart) |
| 40 | # 设置标题 |
| 41 | chart.setTitle('Simple horizontal percent barchart example') |
| 42 | # 开启动画效果 |
| 43 | chart.setAnimationOptions(QChart.SeriesAnimations) |
| 44 | # 添加Series |
| 45 | series = self.getSeries() |
| 46 | chart.addSeries(series) |
| 47 | # 分类 |
| 48 | categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] |
| 49 | # 分类x轴 |
| 50 | axis = QBarCategoryAxis() |
| 51 | axis.append(categories) |
| 52 | # 创建默认轴线 |
| 53 | chart.createDefaultAxes() |
| 54 | # 替换默认y轴 |
| 55 | chart.setAxisY(axis, series) |
| 56 | # 显示图例 |
| 57 | chart.legend().setVisible(True) |
| 58 | chart.legend().setAlignment(Qt.AlignBottom) |
| 59 | |
| 60 | def getSeries(self): |
| 61 | # 创建5个柱子 |