本文整理汇总了Python中reportlab.graphics.charts.piecharts.Pie.width方法的典型用法代码示例。如果您正苦于以下问题:Python Pie.width方法的具体用法?Python Pie.width怎么用?Python Pie.width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.graphics.charts.piecharts.Pie
的用法示例。
在下文中一共展示了Pie.width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def __init__(self, width, height, labels, data):
IRender.__init__(self, width, height, labels, data)
#self.w = self.width
#self.h = self.height
#data = {}
#for value in self.data:
# data[value[0]] = int(value[1])
#plot = cairoplot.PiePlot('/tmp/tmp.png', data, self.w*2, self.h*2, gradient=True)
##plot.font_size *= 2
#plot.render()
#plot.commit()
#with open('/tmp/tmp.png') as f:
# self.image = Image(StringIO(f.read()), self.w, self.h)
pc = Pie()
pc.width = min(self.height,self.width - 150)
pc.height = min(self.height - 50,self.width)
pc.width = pc.height = min(pc.height, pc.width)
pc.x = self.width / 2 - pc.width / 2
pc.y = self.height / 2 - pc.height / 2
pc.data = [int(line[1]) for line in self.data]
pc.labels = [line[0] for line in self.data]
for i in xrange(len(self.data)):
pc.slices[i].fillColor = COLORS[i % len(COLORS)]
pc.slices[i].strokeColor = COLORS[i % len(COLORS)]
self.drawing = Drawing(self.width, self.height)
self.drawing.add(pc)
示例2: test_24_PieCharts
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def test_24_PieCharts(self):
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib import colors
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Spacer, Paragraph
from reportlab.pdfbase import pdfmetrics
from reportlab.graphics.shapes import Drawing
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.graphics.charts.piecharts import Pie
pdfmetrics.registerFont(TTFont('chsFont', 'STHeiti Light.ttc'))
stylesheet = getSampleStyleSheet()
elements = []
doc = SimpleDocTemplate("demo.pdf")
elements.append(Paragraph('<font name="chsFont">JY.zenist.song - 俊毅</font>', stylesheet['Title']))
elements.append(Spacer(1,1*inch))
d = Drawing(400,200)
data = [13,5,20,22,37,45]
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 150
pc.height = 150
pc.data = data
pc.labels = ['a','b','c','d','e','f']
d.add(pc)
elements.append(d)
doc.build(elements)
示例3: draw_time_repartition
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def draw_time_repartition(mandate):
drawing = Drawing(width=180*mm, height=120*mm)
pdf_chart_colors = [HexColor("#fa9d00"), HexColor("#006884"), HexColor("#00909e"), HexColor("#ffd08d"), ]
pie = Pie()
pie.x = 60*mm
pie.y = 35*mm
pie.width = 60*mm
pie.height = 60*mm
pie.slices.strokeWidth = 0.5
pie.slices.fontName = 'Helvetica'
pie.slices.fontSize = 8
pie.data = []
pie.labels = []
titles = []
add_data_and_titles_to_pie(pie, titles, mandate.research_percent, 'research_percent')
add_data_and_titles_to_pie(pie, titles, mandate.tutoring_percent, 'tutoring_percent')
add_data_and_titles_to_pie(pie, titles, mandate.service_activities_percent, 'service_activities_percent')
add_data_and_titles_to_pie(pie, titles, mandate.formation_activities_percent, 'formation_activities_percent')
if len(pie.data) > 0:
drawing.add(pie)
add_legend_to_pie(drawing)
n = len(pie.data)
set_items(n, pie.slices, 'fillColor', pdf_chart_colors)
drawing.legend.colorNamePairs = \
[(pie.slices[i].fillColor, (titles[i], '%0.f' % pie.data[i] + '%')) for i in range(n)]
return drawing
示例4: __add_graph
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def __add_graph(self):
drawing = Drawing(200, 100)
data = list()
labels = list()
self.c.drawString(370, 730,
'Distribucion en pesos'.encode('utf-8'))
for acc in self.accounts:
balance = acc.balance
if acc.currency == 'USD':
balance = balance * self.dolar
data.append(balance)
labels.append(acc.name)
pie = Pie()
pie.x = 280
pie.y = 630
pie.height = 100
pie.width = 100
pie.data = data
pie.labels = labels
pie.simpleLabels = 1
pie.slices.strokeWidth = 1
pie.slices.strokeColor = black
pie.slices.label_visible = 0
legend = Legend()
legend.x = 400
legend.y = 680
legend.dx = 8
legend.dy = 8
legend.fontName = 'Helvetica'
legend.fontSize = 7
legend.boxAnchor = 'w'
legend.columnMaximum = 10
legend.strokeWidth = 1
legend.strokeColor = black
legend.deltax = 75
legend.deltay = 10
legend.autoXPadding = 5
legend.yGap = 0
legend.dxTextSpace = 5
legend.alignment = 'right'
legend.dividerLines = 1|2|4
legend.dividerOffsY = 4.5
legend.subCols.rpad = 30
n = len(pie.data)
self.__setItems(n,pie.slices,
'fillColor',self.pdf_chart_colors)
legend.colorNamePairs = [(pie.slices[i].fillColor,
(pie.labels[i][0:20],'$%0.2f' % pie.data[i])) for i in xrange(n)]
drawing.add(pie)
drawing.add(legend)
x, y = 0, 0
renderPDF.draw(drawing, self.c, x, y, showBoundary=False)
示例5: draw_Pie
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def draw_Pie(story, ProjectID):
d = Drawing(140, 180)
pie = Pie()
pie.sideLabels = 1
pie.labels= get_story_name_list(ProjectID)
pie.data = get_story_count_list(ProjectID)
pie.width = 140
pie.height = 140
pie.y = 0
pie.x = 150
d.add(pie)
story.append(d)
示例6: graphout
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def graphout(prod_catnames, data):
drawing = Drawing(500, 200)
pie = Pie()
pie.sideLabels = 1
pie.labels = prod_catnames
pie.data = data[0]
pie.width = 140
pie.height = 140
pie.y = 35
pie.x = 125
pie.slices.popout = 5
drawing.add(pie)
return drawing
示例7: __init__
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def __init__(self, data, labels):
super(PieChart, self).__init__(400,200)
colors = [
HexColor("#0000e5"),
HexColor("#ff0011"),
HexColor("#800000"),
HexColor("#e05897"),
HexColor("#a08ff7"),
HexColor("#8f8ff5"),
HexColor("#c7c7fa"),
HexColor("#800000"),
HexColor("#eb8585"),
HexColor("#d60a0a"),
HexColor("#ffff00"),
HexColor("#1f1feb"),
]
# Create pie chart
pieChart = Pie()
pieChart.x = 40
pieChart.y = 30
pieChart.width = 120
pieChart.height = 120
pieChart.slices.strokeWidth=0.5
data = json.loads(data)
pieChart.data = data
pieChart.labels = []
labels = json.loads(labels.replace("'",'"'))
for d in data:
pieChart.labels.append(str(d))
# Create legend
legend = Legend()
legend.x = 380
legend.y = 60
legend.boxAnchor = 'se'
legend.subCols[1].align = 'right'
legend.colorNamePairs = []
len_data = len(data)
for i in range(0,len_data):
pieChart.slices[i].fillColor = colors[i]
legend.colorNamePairs.append((colors[i],labels[i]))
self.add(pieChart, "pie chart")
self.add(legend, "legend")
示例8: pie_graph
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def pie_graph(data, elements):
drawing = Drawing(100, 350)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 300
pc.height = 300
pc.data = data
pc.labels = ['a', 'b', 'c', 'd', 'e', 'f']
pc.slices.strokeWidth = 0.5
pc.slices[3].popout = 10
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2, 2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
drawing.add(pc)
elements.append(drawing)
示例9: create_pie
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def create_pie(pie_data):
pie_chart = Drawing(400, 200)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 100
pc.height = 100
pc.data = pie_data["data"]
pc.labels = list(pie_data["label"][0])
pc.slices.strokeWidth=0.5
pc.slices[3].popout = 10
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2,2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
pie_chart.add(pc)
return pie_chart
示例10: piegraph
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def piegraph(elements):
drawing = Drawing(100, 350)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 300
pc.height = 300
pc.data = [10, 20, 30, 40, 50, 60]
pc.labels = ['a', 'b', 'c', 'd', 'e', 'f']
pc.slices.strokeWidth = 0.5
pc.slices[3].popout = 10
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2, 2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
drawing.add(pc)
elements.append(drawing)
elements.append(Spacer(1, 0.7 * inch))
示例11: plpleg
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
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)
示例12: plpleg
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
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)
示例13: generate_certificate
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def generate_certificate(elements):
styles = ParagraphStyle(
name='Normal',
fontName='Helvetica-Bold',
fontSize=15,
alignment=1,
)
elements.append(Spacer(1, 0.5 * inch))
i = Paragraph(str("candidate performance vs average performance"), styles)
elements.append(i)
elements.append(Spacer(1, 0.1 * inch))
drawing = Drawing(0, 200) # for indices
data = [
(13, 5, 20, 22, 37, 45, 19, 4),
(14, 6, 21, 23, 38, 46, 20, 5)
] # data for drawing bar graphs
bc = VerticalBarChart()
bc.x = 0 # x,y define the left bottom of graph
bc.y = 0
bc.height = 150
bc.width = 300
bc.data = data
bc.strokeColor = colors.black
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = 50
bc.valueAxis.valueStep = 10
bc.categoryAxis.labels.boxAnchor = 'ne'
bc.categoryAxis.labels.dx = 6 # next 3 lines is for naming indices
bc.categoryAxis.labels.dy = -2
bc.categoryAxis.labels.angle = 60
bc.categoryAxis.categoryNames = ['Jan-99', 'Feb-99', 'Mar-99',
'Apr-99', 'May-99', 'Jun-99', 'Jul-99', 'Aug-99']
drawing.add(bc)
elements.append(drawing)
elements.append(Spacer(1, 0.5 * inch))
drawing = Drawing(0, 175) # for indices
lc = HorizontalLineChart()
lc.x = 0
lc.y = 10
lc.height = 150
lc.width = 300
lc.data = data
lc.joinedLines = 1
catnames = 'Jan Feb Mar Apr May Jun Jul Aug'.split(' ')
lc.categoryAxis.categoryNames = catnames
lc.categoryAxis.labels.boxAnchor = 'n'
lc.valueAxis.valueMin = 0
lc.valueAxis.valueMax = 60
lc.valueAxis.valueStep = 15
lc.lines[0].strokeWidth = 2
lc.lines[1].strokeWidth = 1.5
drawing.add(lc)
elements.append(drawing)
drawing = Drawing(0, 400) # for indices
data = [
((1, 1), (2, 2), (2.5, 1), (3, 3), (4, 5)),
((1, 2), (2, 3), (2.5, 2), (3.5, 5), (4, 6))
]
elements.append(Spacer(1, 0.1 * inch))
i = Paragraph(str("candidate performance vs average performance"), styles)
elements.append(i)
elements.append(Spacer(1, 0.1 * inch))
lp = LinePlot()
lp.x = 0
lp.y = 50
lp.height = 300
lp.width = 600
lp.data = data
lp.joinedLines = 1
lp.lines[0].symbol = makeMarker('FilledCircle')
lp.lines[1].symbol = makeMarker('Circle')
lp.lineLabelFormat = '%2.0f'
lp.strokeColor = colors.black
lp.xValueAxis.valueMin = 0
lp.xValueAxis.valueMax = 5
lp.xValueAxis.valueSteps = [1, 2, 2.5, 3, 4, 5]
lp.xValueAxis.labelTextFormat = '%2.1f'
lp.yValueAxis.valueMin = 0
lp.yValueAxis.valueMax = 7
lp.yValueAxis.valueSteps = [1, 2, 3, 5, 6]
drawing.add(lp)
elements.append(drawing)
elements.append(Spacer(1, 0.1 * inch))
drawing = Drawing(100, 350)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 300
pc.height = 300
pc.data = [10, 20, 30, 40, 50, 60]
pc.labels = ['a', 'b', 'c', 'd', 'e', 'f']
pc.slices.strokeWidth = 0.5
pc.slices[3].popout = 10
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2, 2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
drawing.add(pc)
elements.append(drawing)
elements.append(Spacer(1, 0.7 * inch))
#.........这里部分代码省略.........
示例14: generar_pdf_busquedas_view
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
def generar_pdf_busquedas_view(request):
print "Genero el PDF"
fecha_m = ""
resultados=[]
fecha_a = ""
b=[]
t=[]
fecha_inicio = x
fecha_final = y
c=0
r=[]
#story =[]
response = HttpResponse(content_type='application/pdf')
pdf_name = "reporte_busqueda.pdf" # llamado clientes
# la linea 26 es por si deseas descargar el pdf a tu computadora
response['Content-Disposition'] = 'attachment; filename=%s' % pdf_name
buff = BytesIO()
doc = SimpleDocTemplate(buff,
pagesize=letter,
rightMargin=40,
leftMargin=40,
topMargin=60,
bottomMargin=18,
)
reportes = []
styles = getSampleStyleSheet()
fichero_imagen="biblioteca/media/images/Reports-banner.jpg"
imagen_logo=Image(os.path.realpath(fichero_imagen),width=400,height=100)
reportes.append(imagen_logo)
header = Paragraph("Fecha del reporte: "+str(date.today()), styles['Heading1'])
header2 = Paragraph("Reporte de las busquedas realizadas entre la fecha "+str(fecha_inicio)+" hasta la fecha "+str(fecha_final) + "\n", styles['Normal'])
salto_linea = Paragraph("\n\n", styles["Normal"])
reportes.append(header)
reportes.append(header2)
reportes.append(Spacer(1, 12))
headings = ('Busqueda', 'Resultado',)# 'Cantidad_Veces_Buscadas')
lista=[]
t = Busqueda.objects.all()
b = Busqueda.objects.filter(fecha__range=(fecha_inicio, fecha_final)).values('busqueda', 'resultados').distinct()
listar=[]
for r in b:
print "llllllllllllllllll",r,"\n"
if r['resultados'] == False:
r['resultados']="No se encontró"
listar.append(r)
else:
r['resultados']="Se encontró"
listar.append(r)
print "lisygyujgyjgjhbjh", listar
#GRAFICAS BARRA
total_busquedas=Busqueda.objects.all().count() #TOTAL BUSQUEDAS
si=Busqueda.objects.filter(resultados=True).count() #BUSUEDAS ENCONTRADAS (SI)
no=total_busquedas-si #BUSQUEDAS NO ENCONTRADAS (NO)
#GRAFICAS PASTEL
for i in b:
print "________________",i.get("busqueda")
for j in t:
print "===============",j.busqueda
if j.busqueda == i.get("busqueda") and j.fecha >= fecha_inicio and j.fecha <= fecha_final:
c = c + 1
print c
lista.append(c)
c=0
print lista , len(lista)
li = zip(b,lista)
'''
#.........这里部分代码省略.........
示例15: Drawing
# 需要导入模块: from reportlab.graphics.charts.piecharts import Pie [as 别名]
# 或者: from reportlab.graphics.charts.piecharts.Pie import width [as 别名]
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2,2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
d.add(pc)
""")
from reportlab.graphics.charts.piecharts import Pie
d = Drawing(200, 100)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 70
pc.height = 70
pc.data = [10,20,30,40,50,60]
pc.labels = ['a','b','c','d','e','f']
pc.slices.strokeWidth=0.5
pc.slices[3].popout = 10
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2,2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
d.add(pc)
draw(d, 'A bare bones pie chart')