Exemple #1
0
    def __init__(self,
                 drawing=None,
                 data=None,
                 x=70,
                 y=25,
                 width=115,
                 height=115):

        pie = Pie()
        pie.strokeColor = white
        pie.slices.strokeColor = white
        pie.slices.popout = 1
        pie.width = width
        pie.height = height
        pie.y = y
        pie.x = x
        pie.sideLabels = 1
        pie.slices.fontName = 'Lato'
        pie.slices.fontSize = 9

        colors = get_n_random_colors(len(data))
        for i in range(0, len(data)):
            pie.slices[i].fillColor = toColor(colors[i])

        pie.data = [value for (_, value) in data]
        pie.labels = [key for (key, _) in data]

        drawing.add(pie)
Exemple #2
0
def draw_pie(data=[], labels=[], use_colors=[], width=360,):
    '''更多属性请查询reportlab.graphics.charts.piecharts.WedgeProperties'''

    pie = Pie()
    pie.x = 60 # x,y饼图在框中的坐标
    pie.y = 20
    pie.slices.label_boxStrokeColor = colors.white  #标签边框的颜色

    pie.data = data      # 饼图上的数据
    pie.labels = labels  # 数据的标签
    pie.simpleLabels = 0 # 0 标签在标注线的右侧;1 在线上边
    pie.sameRadii = 1    # 0 饼图是椭圆;1 饼图是圆形

    pie.slices.strokeColor = colors.red       # 圆饼的边界颜色
    pie.strokeWidth=1                         # 圆饼周围空白区域的宽度
    pie.strokeColor= colors.white             # 整体饼图边界的颜色
    pie.slices.label_pointer_piePad = 10       # 圆饼和标签的距离
    pie.slices.label_pointer_edgePad = 25    # 标签和外边框的距离
    pie.width = width
    pie.direction = 'clockwise'
    pie.pointerLabelMode  = 'LeftRight'
    # for i in range(len(labels)):
    #     pie.slices[i].fontName = 'song' #设置中文
    for i, col in enumerate(use_colors):
         pie.slices[i].fillColor  = col
    return pie
Exemple #3
0
    def __init__(self, drawing=None, data=None):
        #Drawing.__init__(self, width=100, height=175)

        pie = Pie()
        pie.strokeColor = white
        pie.slices.strokeColor = white
        pie.slices.popout = 1
        pie.width = 100
        pie.height = 100
        pie.y = 50
        pie.x = 80

        legend = Legend()
        legend.columnMaximum = 99
        legend.alignment = 'right'
        legend.boxAnchor = 'c'
        legend.dx = 6
        legend.dy = 6
        legend.dxTextSpace = 5
        legend.deltay = 10
        legend.strokeWidth = 0
        legend.strokeColor = white
        legend.subCols[0].minWidth = 75
        legend.subCols[0].align = 'left'
        legend.subCols[1].minWidth = 25
        legend.subCols[1].align = 'right'
        legend.y = 20
        legend.x = 128
        legend.fontName = 'Lato'
        legend.fontSize = 9

        pie.data = data
        pie.slices[0].fillColor = lightgrey
        pie.slices[1].fillColor = limegreen
        pie.slices[1].popout = 6
        pie.slices[2].fillColor = red
        #pie.slices[2].popout = 1

        neutral_pct = positive_pct = negative_pct = 0
        total = sum(data)
        if total > 0:
            neutral_pct = (data[0] / total) * 100.0
            positive_pct = (data[1] / total) * 100.0
            negative_pct = (data[2] / total) * 100.0

        legend.colorNamePairs = [
            (limegreen, ('Positive', '%.1f%%' % positive_pct)),
            (lightgrey, ('Neutral', '%.1f%%' % neutral_pct)),
            (red, ('Negative', '%.1f%%' % negative_pct))
        ]

        drawing.add(pie)
        drawing.add(legend)
Exemple #4
0
def plpleg(i=None):
    from reportlab.lib.colors import pink, red, green
    pie = Pie()
    pie.x = 0
    pie.y = 0
    pie.pointerLabelMode='LeftAndRight'
    pie.slices.label_boxStrokeColor      = red
    pie.simpleLabels = 0
    pie.sameRadii = 1
    pie.data = [1, 0.1, 1.7, 4.2,0,0]
    pie.labels = ['abcdef', 'b', 'c', 'd','e','fedcba']
    pie.strokeWidth=1
    pie.strokeColor=green
    pie.slices.label_pointer_piePad      = 6
    pie.width = 160
    pie.direction = 'clockwise'
    pie.pointerLabelMode  = 'LeftRight'
    return autoLegender(i,pie,pie.slices,None)
def plpleg(i=None):
    from reportlab.lib.colors import pink, red, green
    pie = Pie()
    pie.x = 0
    pie.y = 0
    pie.pointerLabelMode='LeftAndRight'
    pie.slices.label_boxStrokeColor      = red
    pie.simpleLabels = 0
    pie.sameRadii = 1
    pie.data = [1, 0.1, 1.7, 4.2,0,0]
    pie.labels = ['abcdef', 'b', 'c', 'd','e','fedcba']
    pie.strokeWidth=1
    pie.strokeColor=green
    pie.slices.label_pointer_piePad      = 6
    pie.width = 160
    pie.direction = 'clockwise'
    pie.pointerLabelMode  = 'LeftRight'
    return autoLegender(i,pie,pie.slices,None)
def plpleg(i=None):
    from reportlab.lib.colors import pink, red, green

    pie = Pie()
    pie.x = 0
    pie.y = 0
    pie.pointerLabelMode = "LeftAndRight"
    pie.slices.label_boxStrokeColor = red
    pie.simpleLabels = 0
    pie.sameRadii = 1
    pie.data = [1, 0.1, 1.7, 4.2, 0, 0]
    pie.labels = ["abcdef", "b", "c", "d", "e", "fedcba"]
    pie.strokeWidth = 1
    pie.strokeColor = green
    pie.slices.label_pointer_piePad = 6
    pie.width = 160
    pie.direction = "clockwise"
    pie.pointerLabelMode = "LeftRight"
    return autoLegender(i, pie, pie.slices, None)
Exemple #7
0
    def __init__(self, drawing=None, title=None, data=None, bench_data=None):

        pie = Pie()
        pie.strokeColor = white
        pie.slices.strokeColor = white
        pie.slices.popout = 1
        pie.width = 85
        pie.height = 85
        pie.y = 50
        pie.x = 35

        bench_pie = Pie()
        bench_pie.strokeColor = white
        bench_pie.slices.strokeColor = white
        bench_pie.slices.popout = 1
        bench_pie.width = 85
        bench_pie.height = 85
        bench_pie.y = 50
        bench_pie.x = 150

        legend = Legend()
        legend.columnMaximum = 99
        legend.alignment = 'right'
        legend.boxAnchor = 'c'
        legend.dx = 6
        legend.dy = 6
        legend.dxTextSpace = 5
        legend.deltay = 10
        legend.strokeWidth = 0
        legend.strokeColor = white
        legend.subCols[0].minWidth = 75
        legend.subCols[0].align = 'left'
        legend.subCols[1].minWidth = 25
        legend.subCols[1].align = 'right'
        legend.y = 20
        legend.x = 153
        legend.fontName = 'Lato'
        legend.fontSize = 9

        pie.data = data
        pie.slices[0].fillColor = lightgrey
        pie.slices[1].fillColor = limegreen
        #pie.slices[1].popout    = 6
        pie.slices[2].fillColor = red

        bench_pie.data = bench_data
        bench_pie.slices[0].fillColor = lightgrey
        bench_pie.slices[1].fillColor = limegreen
        #bench_pie.slices[1].popout    = 6
        bench_pie.slices[2].fillColor = red

        legend.colorNamePairs = [(limegreen, 'Positive'),
                                 (lightgrey, 'Neutral'), (red, 'Negative')]

        drawing.add(
            String(x=75,
                   y=145,
                   text=title,
                   fontSize=10,
                   fontName='Lato',
                   textAnchor='middle'))
        drawing.add(
            String(x=165,
                   y=145,
                   text='Benchmark',
                   fontSize=10,
                   fontName='Lato'))

        drawing.add(pie)
        drawing.add(bench_pie)
        drawing.add(legend)