代码拉取完成,页面将自动刷新
同步操作将从 PyQt5/PyQt 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019/10/2
@author: Irony
@site: https://pyqt5.com , https://github.com/892768447
@email: 892768447@qq.com
@file: BarChart
@description: 柱状图表
"""
from PyQt5.QtChart import QChartView, QChart, QBarSet, QBarSeries, QBarCategoryAxis
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter
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 barchart example')
# 开启动画效果
chart.setAnimationOptions(QChart.SeriesAnimations)
# 添加Series
series = self.getSeries()
chart.addSeries(series)
# 分类
categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
# 分类x轴
axis = QBarCategoryAxis()
axis.append(categories)
# 创建默认轴线
chart.createDefaultAxes()
# 替换默认x轴
chart.setAxisX(axis, series)
# 显示图例
chart.legend().setVisible(True)
chart.legend().setAlignment(Qt.AlignBottom)
def getSeries(self):
# 创建5个柱子
set0 = QBarSet('Jane')
set1 = QBarSet('John')
set2 = QBarSet('Axel')
set3 = QBarSet('Mary')
set4 = QBarSet('Samantha')
# 添加数据
set0 << 1 << 2 << 3 << 4 << 5 << 6
set1 << 5 << 0 << 0 << 4 << 0 << 7
set2 << 3 << 5 << 8 << 13 << 8 << 5
set3 << 5 << 6 << 7 << 3 << 4 << 5
set4 << 9 << 7 << 5 << 3 << 1 << 2
# 创建柱状条
series = QBarSeries()
series.append(set0)
series.append(set1)
series.append(set2)
series.append(set3)
series.append(set4)
return series
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。