开发者

PyQt5+QtChart实现柱状图的绘制

目录
  • 柱状图分类
  • 实现代码
  • 效果图

柱状图分类

QBarSeries:竖向柱状图

QPercentBarSeries:竖向百分比柱状图

QStackedBarSeries:竖向堆叠柱状图

QHorizontalBarSeries:横向柱状图

QHorizontalPercentBarSeries:横向百分比柱状图

QHorizontalStackedBarSeries:横向堆叠柱状图

实现代码

import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QBarSet, QBarSeries, QChart, QChartView, QValueAxis, QBjavascriptarCategoryAxis,\
          QBarLegendMarker, QvbarModelMapper, QHBarModelMapper, QHorizontalBarSeries,QPercentBarSeries, \
          QHorizontalPercentBarSeries, QHorizontalStackedBarSeries,QStackedBarSeries

class MyBarWindow(QWidget):
    def __init__(self, parent=None):
        super(MyBarWindow, self).__init__(parent)

        chart = QChart()
        barSeries = QBarSeries()    # 竖向柱状图
        # barSeries = QPercentBarSeries(javascript)   # 竖向百分比柱状图
        # barSeries = QHorizontalBarSeries()    # 横向柱状图
        # barSeries = QHorizontalPercentBarSeries()   # 横向百分比柱状图
        # barSeries = QStackedBarSeries() # 竖向堆叠柱状图
        # barSeries = QHorizontalStackedBarSeries(http://www.devze.com) # 横向堆叠柱状图

        chartView = QChartView()
        valueAxisY = QValueAxis()
        barCategorAxisX = QBarCategoryAxis()

        chart.setAnimationOptions(QChart.AllAnimations)
        chart.setAnimationEasingCurve(QEasingCurve.OutBack)
        
        set0 = QBarSet("产品1")
        set1 = QBarSet("产品2")
        set2 = QBarSet("产品3")

        set0.append(10.12345)
        set0.append(3.23)
        set0.append(7)

        set1.append(5)
        set1.append(2)
     开发者_自学开发   set1.append(9)

        set2.append(9)
        set2.append(1)
        set2.append(7)

        barSeries.append(set0)
        barSeries.append(set1)
        barSeries.append(set2)
        barSeries.setBarWidth(0.8)

        barSeries.setLabelsVisible(True)
        barSeries.setLabelsAngle(75.0)
       android barSeries.setLabelsPrecision(3)
        # barSeries.setLabelsFormat("")
        
        barCategorAxisX.append(["一季度", "二季度", "三季度"])

        valueAxisY.setRange(0, 10)

        chart.setTitle("柱状图表")
        chart.setAxisX(barCategorAxisX)
        chart.setAxisY(valueAxisY)
        chart.addSeries(barSeries)

        chartView.setChart(chart)

        vbox = QVBoxLayout()
        vbox.addwidget(chartView)
        self.setLayout(vbox)
        

if __name__ == "__main__":
    app = QApplication(sys.argv)编程
    win = MyBarWindow()
    win.show()
    sys.exit(app.exec_())

效果图

竖向柱状图

PyQt5+QtChart实现柱状图的绘制

竖向百分比柱状图

PyQt5+QtChart实现柱状图的绘制

竖向堆叠柱状图

PyQt5+QtChart实现柱状图的绘制

横向柱状图

PyQt5+QtChart实现柱状图的绘制

横向百分比柱状图

PyQt5+QtChart实现柱状图的绘制

横向堆叠柱状图

PyQt5+QtChart实现柱状图的绘制

到此这篇关于PyQt5+QtChart实现柱状图的绘制的文章就介绍到这了,更多相关PyQt5 QtChart柱状图内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新开发

开发排行榜