コード例 #1
0
    def __init__(self, width=400, height=200, *args, **kw):
        Drawing.__init__(*(self, width, height) + args, **kw)
        bc = HorizontalBarChart()
        bc.x = 50
        bc.y = 50
        bc.height = 125
        bc.width = 300
        bc.data = dataSample5
        bc.strokeColor = colors.black

        bc.useAbsolute = 1
        bc.barWidth = 10
        bc.groupSpacing = 20
        bc.barSpacing = 10

        bc.valueAxis.valueMin = 0
        bc.valueAxis.valueMax = 60
        bc.valueAxis.valueStep = 15

        bc.categoryAxis.labels.boxAnchor = 'e'
        bc.categoryAxis.categoryNames = ['Ying', 'Yang']

        self.add(bc, name='HBC')
コード例 #2
0
                    def generate_page1(c):
                        #Image----------------------------------------------------------------------
                        im1 = Image.open("left.jpg")
                        c.drawInlineImage(im1,
                                          10,
                                          15,
                                          width=546 / 2.3,
                                          height=1290 / 2.3)

                        im2 = Image.open("shinken.jpg")
                        c.drawInlineImage(im2,
                                          259,
                                          height - 183,
                                          width=2434 / 4.4,
                                          height=725 / 4.4)

                        im3 = Image.open("skor.jpg")
                        c.drawInlineImage(im3,
                                          259,
                                          height - 251,
                                          width=2335 / 4.2,
                                          height=271 / 4.2)

                        im4 = Image.open("diagram.jpg")
                        c.drawInlineImage(im4,
                                          259,
                                          15,
                                          width=2339 / 4.2,
                                          height=1367 / 4.2)

                        #grafik1----------------------------------------------------------------------

                        from reportlab.graphics.shapes import Drawing
                        from reportlab.graphics.charts.barcharts import HorizontalBarChart

                        drawing = Drawing(500, 250)
                        data = [(N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11,
                                 N12, N13, N14, N15, N16, N17)]
                        bc = HorizontalBarChart()
                        bc.x = 100
                        bc.y = 100
                        bc.height = 250
                        bc.width = 300
                        bc.data = data
                        bc.strokeColor = None
                        bc.fillColor = None
                        #                        bc.bars[0].fillColor = PCMYKColor(92,47,0,33,alpha=95)
                        #                        bc.bars[0].strokeColor = PCMYKColor(92,47,0,33,alpha=95)
                        #                        bc.bars[0].fillColor = PCMYKColor(92,32,0,33,alpha=95)
                        #                        bc.bars[0].strokeColor = PCMYKColor(92,32,0,33,alpha=95)
                        bc.bars[0].fillColor = PCMYKColor(92,
                                                          16,
                                                          0,
                                                          33,
                                                          alpha=95)
                        bc.bars[0].strokeColor = PCMYKColor(92,
                                                            16,
                                                            0,
                                                            33,
                                                            alpha=95)
                        #                        bc.bars[0].fillColor = PCMYKColor(92,7,0,33,alpha=95)
                        #                        bc.bars[0].strokeColor = PCMYKColor(92,7,0,33,alpha=95)
                        bc.barWidth = 15
                        bc.valueAxis.valueMin = 0
                        bc.valueAxis.valueMax = 100
                        bc.valueAxis.valueStep = 10
                        bc.valueAxis.visibleAxis = False
                        bc.valueAxis.visibleGrid = False
                        bc.valueAxis.visibleTicks = False
                        bc.valueAxis.forceZero = True
                        bc.valueAxis.visibleLabels = 0

                        bc.categoryAxis.visibleGrid = False
                        bc.categoryAxis.visibleTicks = False  # hidding the ticks remove the label
                        bc.categoryAxis.tickLeft = 0  # a workaround is to set the tick length
                        bc.categoryAxis.tickRight = 0  # to zero.
                        bc.categoryAxis.strokeWidth = 0.25
                        bc.categoryAxis.labelAxisMode = 'low'
                        bc.categoryAxis.labels.textAnchor = 'end'
                        bc.categoryAxis.labels.angle = 0
                        bc.categoryAxis.labels.fontName = 'Designosaur-Regular'
                        #bc.categoryAxis.labels.fontColor    = PCMYKColor(0,65,100,0,alpha=90)
                        bc.categoryAxis.labels.boxAnchor = 'e'
                        bc.categoryAxis.labels.dx = -5
                        bc.categoryAxis.labels.dy = 0
                        bc.categoryAxis.labels.angle = 0
                        bc.categoryAxis.reverseDirection = 1
                        bc.categoryAxis.joinAxisMode = 'left'
                        bc.categoryAxis.categoryNames = [
                            NN1, NN2, NN3, NN4, NN5, NN6, NN7, NN8, NN9, NN10,
                            NN11, NN12, NN13, NN14, NN15, NN16, NN17
                        ]

                        bc.barLabels.fontName = 'Designosaur-Regular'
                        bc.barLabels.fontSize = 10
                        bc.barLabels.angle = 0
                        bc.barLabelFormat = "%.00f%%"
                        bc.barLabels.boxAnchor = 'w'
                        bc.barLabels.boxFillColor = None
                        bc.barLabels.boxStrokeColor = None
                        bc.barLabels.dx = 10
                        bc.barLabels.dy = 0
                        #bc.barLabels.dy            = -1
                        bc.barLabels.boxTarget = 'hi'

                        drawing.add(bc)
                        drawing.wrapOn(c, width, height)
                        drawing.drawOn(c, 350, height - 650)

                        #Table---------------------------------------------------------------------

                        styleBH = styles["Normal"]
                        styleBH.alignment = TA_CENTER
                        styleBH.fontSize = 12
                        styleBH.fontName = 'Designosaur-Regular'
                        #styleBH.textColor = PCMYKColor(92,7,0,33,alpha=100)
                        isi1 = Paragraph(nama, styleBH)
                        isitabel1 = [[isi1]]
                        table1 = Table(isitabel1, colWidths=[150])
                        table1.wrapOn(c, width, height)
                        table1.drawOn(c, 54, height - 352)

                        isi2 = Paragraph(kelas, styleBH)
                        isitabel2 = [[isi2]]
                        table2 = Table(isitabel2, colWidths=[150])
                        table2.wrapOn(c, width, height)
                        table2.drawOn(c, 54, height - 386)

                        isi3 = Paragraph(sekolah, styleBH)
                        isitabel3 = [[isi3]]
                        table3 = Table(isitabel3, colWidths=[150])
                        table3.wrapOn(c, width, height)
                        table3.drawOn(c, 54, height - 421)

                        isi4 = Paragraph(outlet, styleBH)
                        isitabel4 = [[isi4]]
                        table4 = Table(isitabel4, colWidths=[150])
                        table4.wrapOn(c, width, height)
                        table4.drawOn(c, 54, height - 455)

                        #Text----------------------------------------------------------------------

                        #nilai total
                        c.setFillColor(white)
                        c.setStrokeColor(white)
                        if (NTotal == '10.0'):
                            c.setFont("Designosaur-Regular", 35)
                            c.drawString(352, height - 230, NTotal + "/")
                            c.setFont("Designosaur-Regular", 20)
                            c.drawString(395, height - 235, "10")
                        else:
                            c.setFont("Designosaur-Regular", 35)
                            c.drawString(338, height - 230, NTotal + "/")
                            c.setFont("Designosaur-Regular", 20)
                            c.drawString(415, height - 235, "10")

                        #Yang paling tidak dikuasai siswa
                        c.setFont("Designosaur-Regular", 9)
                        c.drawString(
                            576, height - 205,
                            "Topik yang paling tidak dikuasai peserta Try-Out II :"
                        )
                        c.drawString(576, height - 216,
                                     "1. Mean, Median, dan Modus")
                        c.drawString(576, height - 227, "2. Debit Air")
                        c.drawString(576, height - 238, "3. Bangun Ruang")