def subtest(sa, d): pc = Pie() pc.direction = d pc.startAngle = sa arcs = _makeSideArcDefs(sa, d) A = [x[1] for x in pc.makeAngles()] arcsum = sum([a[2] - a[1] for a in arcs]) isum = intSum(arcs, A) mi = max([a[2] - a[1] for a in arcs]) ni = min([a[2] - a[1] for a in arcs]) l = [] s = arcsum - 360 if s > 1e-8: l.append("Arc length=%s != 360" % s) s = abs(isum - 360) if s > 1e-8: l.append("interval intersection length=%s != 360" % s) if mi > 360: l.append("max interval intersection length=%s >360" % mi) if ni < 0: l.append("min interval intersection length=%s <0" % ni) if l: l.append("sa: %s d: %s" % (sa, d)) l.append("sidearcs: %s" % str(arcs)) l.append("Angles: %s" % A) raise ValueError("piecharts._makeSideArcDefs failure\n%s" % "\n".join(l))
def get_pie_image(width, height, x, y, datas, lables, _colors): """ ��ɱ�״ͼ @param width: ͼƬ��� @param height: ͼƬ�Ŀ�� @param x: ͼƬ��x��� @param y: ͼƬ��y��� @param datas: ���ͼƬ����� @param lables: ��״ͼ��������� """ from reportlab.graphics.charts.piecharts import Pie drawing = Drawing(width, height) pc = Pie() pc.width = 80 pc.height = 80 pc.x = x pc.y = y pc.data = datas pc.labels = lables pc.slices.strokeWidth = 0.5 pc.startAngle = 90 pc.checkLabelOverlap = True pc.sideLabels = True pc.sideLabelsOffset = 0.1 pc.direction = 'clockwise' for i in range(len(lables)): pc.slices[i].fontName = "msyh" pc.slices[i].fontSize = 3 pc.slices[i].labelRadius = 3 pc.slices[i].popout = 5 pc.slices[i].fillColor = _colors[i] drawing.add(pc) return drawing
def pdf_drawPie(self, pie_data, pie_lable=[], colors=[], x=805, y=1650, width=900, height=900, innerRadiusFraction=0.5): ''' @example: chart_data = [1212,66,585,225,36] lable = ['dfd','sdd','trtr','rrrr','ytytyt'] self.pdf_drawPie(chart_data,lable) ''' if len(pie_data) == 0 or sum(pie_data) == 0: return d = Drawing(200, 100) pc = Pie() pc.x = 65 pc.y = 65 pc.width = width pc.height = height pc.data = pie_data pc.labels = pie_lable pc.startAngle = 0 pc.sideLabels = 1 pc.simpleLabels = 0 if len(colors) != len(pie_data): colors = [] for i in range(len(pie_data)): colors.append(HexColor(self.randomcolor())) for i in range(0, len(pie_data)): pc.slices[i].fontSize = 40 pc.slices[i].fontName = FONT pc.slices[i].fillColor = colors[i] pc.slices[i].strokeColor = colors[i] pc.innerRadiusFraction = innerRadiusFraction d.add(pc) d.drawOn(self.pdf_page_object, x, y)
def subtest(sa,d): pc = Pie() pc.direction=d pc.startAngle=sa arcs = _makeSideArcDefs(sa,d) A = [x[1] for x in pc.makeAngles()] arcsum = sum([a[2]-a[1] for a in arcs]) isum = intSum(arcs,A) mi = max([a[2]-a[1] for a in arcs]) ni = min([a[2]-a[1] for a in arcs]) l = [] s = (arcsum-360) if s>1e-8: l.append('Arc length=%s != 360' % s) s = abs(isum-360) if s>1e-8: l.append('interval intersection length=%s != 360' % s) if mi>360: l.append('max interval intersection length=%s >360' % mi) if ni<0: l.append('min interval intersection length=%s <0' % ni) if l: l.append('sa: %s d: %s' % (sa,d)) l.append('sidearcs: %s' % str(arcs)) l.append('Angles: %s' % A) raise ValueError('piecharts._makeSideArcDefs failure\n%s' % '\n'.join(l))
def torta(datos): tamanio = datos["tamanio"] data = datos["data"] labels = datos["labels"] colores = datos["colores"] titulo = datos["titulo"] grafico = Pie() grafico.x = 10 grafico.y = 10 grafico.startAngle = 45 grafico.width = tamanio grafico.height = tamanio grafico.data = data grafico.labels = labels grafico.slices.fontName = "Helvetica" grafico.slices.fontSize = FONTSIZE grafico.simpleLabels = False grafico.sideLabels = 1 grafico.sideLabelsOffset = 0.075 grafico.slices.label_simple_pointer = False grafico.slices.label_pointer_elbowLength = 0.5 grafico.slices.label_pointer_piePad = 3 grafico.slices.label_pointer_edgePad = 3 grafico.slices.label_pointer_strokeColor = colors.black grafico.slices.label_pointer_strokeWidth = 0.75 grafico.slices.strokeWidth=1.5 grafico.slices.strokeColor=colors.white for i in range(len(colores)): grafico.slices[i].fillColor = colors.HexColor(colores[i]) retorno = crearDrawing(grafico) if titulo: etiqueta = Label() etiqueta.fontSize = FONTSIZE etiqueta.fontName = "Helvetica-Bold" etiqueta.setText(titulo) etiquetar(retorno, etiqueta, tamanio/2.0, 0.0) return retorno