示例#1
0
        def __init__(self, parent=None):
            super(Widget, self).__init__(parent)
            self.setWindowTitle('Financieële grafieken externe werken')
            self.setWindowIcon(QIcon('./images/logos/logo.jpg'))
            self.setWindowFlags(self.windowFlags() | Qt.WindowSystemMenuHint
                                | Qt.WindowMinMaxButtonsHint)

            grid = QGridLayout()
            grid.setSpacing(20)

            metadata = MetaData()
            resultaten = Table('resultaten', metadata,
                               Column('resID', Integer(), primary_key=True),
                               Column('statusweek', String),
                               Column('btotaal', Float),
                               Column('wtotaal', Float),
                               Column('betaald_bedrag', Float),
                               Column('meerminderwerk', Float),
                               Column('onderhandenwerk', Float),
                               Column('aanneemsom', Float),
                               Column('blonen', Float),
                               Column('wlonen', Float),
                               Column('bmaterialen', Float),
                               Column('wmaterialen', Float),
                               Column('bmaterieel', Float),
                               Column('wmaterieel', Float),
                               Column('bprojectkosten', Float),
                               Column('wprojectkosten', Float),
                               Column('binhuur', Float),
                               Column('winhuur', Float),
                               Column('bdiensten', Float),
                               Column('wdiensten', Float),
                               Column('bruto_winst', Float),
                               Column('boekweek', String))
            params = Table('params', metadata,
                           Column('paramID', Integer(), primary_key=True),
                           Column('tarief', String))
            engine = create_engine(
                'postgresql+psycopg2://postgres@localhost/bisystem')
            con = engine.connect()

            selpar1 = select([params]).where(params.c.paramID == 97)
            rppar1 = con.execute(selpar1).first()
            bo_incr = rppar1[1] / 52  #begrote omzet per week
            selpar2 = select([params]).where(params.c.paramID == 98)
            rppar2 = con.execute(selpar2).first()
            bw_incr = rppar2[1] / 52  #begrote winst per week

            jaar = jrwk[0:4]
            engine = create_engine(
                'postgresql+psycopg2://postgres@localhost/bisystem')
            con = engine.connect()
            selres = select([resultaten]).where(and_(resultaten.c.boekweek == jrwk,\
              resultaten.c.statusweek.like(jaar+'%'))).order_by(resultaten.c.statusweek)
            rpres = con.execute(selres)
            if keuze == '1':
                s1 = 2
                s2 = 3
                t1 = 'Kosten totaal begroot'
                t2 = 'Kosten totaal werkelijk'
                t3 = 'Kosten totaal '
                ysch = 160000000
            elif keuze == '2':
                s1 = 8
                s2 = 9
                t1 = 'Lonen begroot'
                t2 = 'Lonen werkelijk'
                t3 = 'Lonen '
                ysch = 100000000
            elif keuze == '3':
                s1 = 10
                s2 = 11
                t1 = 'Materialen begroot'
                t2 = 'Materialen werkelijk'
                t3 = 'Materialen'
                ysch = 60000000
            elif keuze == '4':
                s1 = 12
                s2 = 13
                t1 = 'Materiëel begroot'
                t2 = 'Materiëel werkelijk'
                t3 = 'Materiëel '
                ysch = 20000000
            elif keuze == '5':
                s1 = 16
                s2 = 17
                t1 = 'Inhuur begroot'
                t2 = 'Inhuur werkelijk'
                t3 = 'Inhuur '
                ysch = 30000000
            elif keuze == '6':
                s1 = 18
                s2 = 19
                t1 = 'Diensten begroot'
                t2 = 'Diensten werkelijk'
                t3 = 'Diensten '
                ysch = 30000000
            elif keuze == '7':
                s1 = 14
                s2 = 15
                t1 = 'Projektkosten begroot'
                t2 = 'Projektkosten werkelijk'
                t3 = 'Projektkosten '
                ysch = 10000000
            elif keuze == '8':
                y3 = [
                    0,
                ]
                y3val = 0
                x1 = [
                    0,
                ]
                xval1 = 0
                # prognose winst
                for teller in range(0, 53):
                    y3val = y3val + bw_incr
                    y3 = y3 + [(y3val)]
                    xval1 = xval1 + 1
                    x1 = x1 + [(xval1)]
                s1 = 20
                s2 = 20
                t1 = 'Bruto winst prognose'
                t2 = 'Bruto winst actueel'
                t3 = 'Bruto winst - prognose / aktueel '
                ysch = 20000000
            elif keuze == '9':
                s1 = 6
                s2 = 4
                t1 = 'Onderhandenwerk'
                t2 = 'Betaald bedrag'
                t3 = 'Onderhandenwerk - Betaald bedrag '
                ysch = 160000000
            elif keuze == 'A':
                y4 = [
                    0,
                ]
                y4val = 0
                x2 = [
                    0,
                ]
                xval2 = 0
                #prognose omzet
                for teller in range(0, 53):
                    y4val = y4val + bo_incr
                    y4 = y4 + [(y4val)]
                    xval2 = xval2 + 1
                    x2 = x2 + [(xval2)]
                s1 = 7
                s2 = 7
                t1 = 'Omzet prognose'
                t2 = 'Omzet aktueel'
                t3 = 'Omzet '
                ysch = 160000000
            elif keuze == 'B':
                s1 = 20
                s2 = 5
                t1 = 'Bruto winst werkelijk'
                t2 = 'Meerminderwerk'
                t3 = 'Bruto winst werkelijk / Meerminderwerk '
                ysch = 30000000

            x = [
                0,
            ]
            y1 = [
                0,
            ]
            y2 = [
                0,
            ]
            idx = 0
            yval1 = 0
            yval2 = 0
            for row in rpres:
                yval1 = y1[idx] + row[s1]
                y1 = y1 + [(yval1)]
                yval2 = y2[idx] + row[s2]
                y2 = y2 + [(yval2)]
                x = x + [(int(row[1][4:]))]
                idx += 1

            series1 = QLineSeries()
            if keuze == '8':
                for t, val in zip(x1, y3):
                    series1.append(int(t), val)
            elif keuze == 'A':
                for t, val in zip(x2, y4):
                    series1.append(int(t), val)
            else:
                for t, val in zip(x, y1):
                    series1.append(int(t), val)
            series2 = QLineSeries()
            for t, val in zip(x, y2):
                series2.append(int(t), val)

            chart = QChart()
            chart.addSeries(series1)
            chart.addSeries(series2)

            series1.setColor(QColor(Qt.red))
            series2.setColor(QColor(Qt.blue))
            series1.setName(t1)
            series2.setName(t2)
            chart.legend().setVisible(True)

            font = QFont()
            font.setPixelSize(22)
            chart.setTitleFont(font)
            chart.setTitle(t3 + jaar)
            chart.setTitleBrush(QBrush(Qt.black))
            chart.legend().setLabelBrush(QColor(Qt.black))

            axisX = QCategoryAxis()
            axisY = QCategoryAxis()

            axisX.setTitleText('Jaar ' + jaar + ' - Weeknummers')
            axisX.setTitleBrush(QBrush(Qt.black))
            font = QFont("Sans Serif")
            axisX.setTitleFont(font)

            axisPen = QPen(QColor(100, 100, 100))  # 100,100,100
            axisPen.setWidth(3)
            axisX.setLinePen(axisPen)
            axisY.setLinePen(axisPen)

            axisBrush = QBrush(Qt.black)
            axisX.setLabelsBrush(axisBrush)
            axisY.setLabelsBrush(axisBrush)

            axisX.setGridLineVisible(False)
            axisY.setGridLineVisible(True)
            axisX.setShadesBrush(QBrush(QColor(245, 245, 245)))
            axisX.setShadesVisible(True)
            axisX.append(jaar + "-01", 1)
            axisX.append(jaar + "-02", 2)
            axisX.append(jaar + "-03", 3)
            axisX.append(jaar + "-04", 4)
            axisX.append(jaar + "-05", 5)
            axisX.append(jaar + "-06", 6)
            axisX.append(jaar + "-07", 7)
            axisX.append(jaar + "-08", 8)
            axisX.append(jaar + "-09", 9)
            axisX.append(jaar + "-10", 10)
            axisX.append(jaar + "-11", 11)
            axisX.append(jaar + "-12", 12)
            axisX.append(jaar + "-13", 13)
            axisX.append(jaar + "-14", 14)
            axisX.append(jaar + "-15", 15)
            axisX.append(jaar + "-16", 16)
            axisX.append(jaar + "-17", 17)
            axisX.append(jaar + "-18", 18)
            axisX.append(jaar + "-19", 19)
            axisX.append(jaar + "-20", 20)
            axisX.append(jaar + "-21", 21)
            axisX.append(jaar + "-22", 22)
            axisX.append(jaar + "-23", 23)
            axisX.append(jaar + "-24", 24)
            axisX.append(jaar + "-25", 25)
            axisX.append(jaar + "-26", 26)
            axisX.append(jaar + "-27", 27)
            axisX.append(jaar + "-28", 28)
            axisX.append(jaar + "-29", 29)
            axisX.append(jaar + "-30", 30)
            axisX.append(jaar + "-31", 31)
            axisX.append(jaar + "-32", 32)
            axisX.append(jaar + "-33", 33)
            axisX.append(jaar + "-34", 34)
            axisX.append(jaar + "-35", 35)
            axisX.append(jaar + "-36", 36)
            axisX.append(jaar + "-37", 37)
            axisX.append(jaar + "-38", 38)
            axisX.append(jaar + "-39", 39)
            axisX.append(jaar + "-40", 40)
            axisX.append(jaar + "-41", 41)
            axisX.append(jaar + "-42", 42)
            axisX.append(jaar + "-43", 43)
            axisX.append(jaar + "-44", 44)
            axisX.append(jaar + "-45", 45)
            axisX.append(jaar + "-46", 46)
            axisX.append(jaar + "-47", 47)
            axisX.append(jaar + "-48", 48)
            axisX.append(jaar + "-49", 49)
            axisX.append(jaar + "-50", 50)
            axisX.append(jaar + "-51", 51)
            axisX.append(jaar + "-52", 52)
            axisX.append(jaar + "-53", 53)
            axisX.setRange(0, 53)
            axisX.setLabelsAngle(-90)

            axisY = QValueAxis()
            axisY.setTickCount(33)
            axisY.setTitleText("Bedragen in Euro")
            axisY.setTitleFont(font)
            axisY.setLabelFormat('%d')
            axisY.setTitleBrush(QBrush(Qt.black))
            axisY.setRange(0, ysch)

            Lfont = QFont("Sans Serif")
            Dfont = QFont("Sans Serif")
            Lfont.setPixelSize(10)
            Dfont.setPixelSize(10)
            axisX.setLabelsFont(Dfont)
            axisY.setLabelsFont(Lfont)

            axisPen = QPen(QColor('black'))
            axisPen = QPen()
            axisPen.setWidth(2)
            axisX.setLinePen(axisPen)
            axisX.setLabelsColor(QColor('black'))
            axisY.setLinePen(axisPen)
            axisY.setLabelsColor(QColor('black'))

            chart.addAxis(axisX, Qt.AlignBottom)
            series1.attachAxis(axisX)
            axisX.setLabelsAngle(-90)

            chart.addAxis(axisY, Qt.AlignLeft)
            series1.attachAxis(axisY)
            series2.attachAxis(axisY)

            self.chartView = QChartView(chart)
            self.chartView.setRenderHint(QPainter.Antialiasing)

            buttonPreview = QPushButton('Afdrukvoorbeeld')
            buttonPreview.clicked.connect(self.handle_preview)
            buttonPreview.setStyleSheet(
                "color: black;  background-color: gainsboro")
            buttonPrint = QPushButton('Printen')
            buttonPrint.clicked.connect(self.handle_print)
            buttonPrint.setStyleSheet(
                "color: black;  background-color: gainsboro")
            buttonSluit = QPushButton('Sluiten')
            buttonSluit.clicked.connect(lambda: sluit(self, m_email))
            buttonSluit.setStyleSheet(
                "color: black;  background-color: gainsboro")
            grid.addWidget(self.chartView, 0, 0, 0, 3)
            grid.addWidget(buttonSluit, 1, 0)
            grid.addWidget(buttonPrint, 1, 1)
            grid.addWidget(buttonPreview, 1, 2)

            self.setLayout(grid)
            self.setGeometry(200, 40, 1395, 930)
示例#2
0
def customAxisY(chart):
    # 自定义y轴(不等分)
    series = chart.series()
    if not series:
        return
    category = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
    axisy = QCategoryAxis(
        chart, labelsPosition=QCategoryAxis.AxisLabelsPositionOnValue)
    axisy.setGridLineVisible(False)  # 隐藏网格线条
    axisy.setTickCount(len(category))  # 设置刻度个数
    miny = chart.axisY().min()
    maxy = chart.axisY().max()
    tickc = axisy.tickCount()
    if tickc < 2:
        axisy.append(category[0])
    else:
        step = (maxy - miny) / (tickc - 1)  # tickc>=2
        for i in range(0, tickc):
            axisy.append(category[i], miny + i * step)
    chart.addAxis(axisy, Qt.AlignRight)  # 添加到右侧
    series[-1].attachAxis(axisy)  # 附加到series上