本文整理汇总了Python中reportlab.graphics.charts.legends.Legend.columnMaximum方法的典型用法代码示例。如果您正苦于以下问题:Python Legend.columnMaximum方法的具体用法?Python Legend.columnMaximum怎么用?Python Legend.columnMaximum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.graphics.charts.legends.Legend
的用法示例。
在下文中一共展示了Legend.columnMaximum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addAutoLegend
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
def addAutoLegend(self,chart,offset,num,side='bottom'):
from reportlab.lib.validators import Auto
width = 300
height = 150
legend = Legend()
if side == 'bottom':
legend.x = offset[0]-15
legend.dx = 20
legend.dy = 5
legend.y = offset[1]-25
legend.deltax = None
legend.autoXPadding = 35
legend.deltay = 5
legend.boxAnchor = 'nw'
legend.dxTextSpace = 5
legend.columnMaximum = (num/3)
if num%3 >0:
legend.columnMaximum += 1
legend.variColumn = True
elif side == 'right':
legend.x = offset[0]+offset[2]+40
legend.dx = 20
legend.dy = 5
legend.y = offset[1]+offset[3]-15
legend.deltax = None
legend.deltay = 5
legend.boxAnchor = 'nw'
legend.dxTextSpace = 5
legend.columnMaximum = 9
legend.colorNamePairs=Auto(chart=chart)
return legend
示例2: make_legend
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
def make_legend(self, drawing, chart):
if not self.legend_labels:
return
# Get legend labels
labels = self.get_legend_labels()
# Legend object
legend = Legend()
legend.colorNamePairs = zip(self.colors[:len(labels)], labels)
legend.columnMaximum = len(legend.colorNamePairs)
legend.deltay = 5
legend.alignment = 'right'
legend.x = drawing.width + 40
legend.y = drawing.height - (self.title and self.title.get('height', DEFAULT_TITLE_HEIGHT) or 0)
# Sets legend extra attributes if legend_labels is a dictionary
if isinstance(self.legend_labels, dict):
for k,v in self.legend_labels.items():
if k != 'labels' and v:
setattr(legend, k, v)
drawing.add(legend)
return legend
示例3: legend_draw
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
def legend_draw(self, labels, chart, **kwargs):
legend = Legend()
chart_type = kwargs['type']
legend.fontName = 'FreeSans'
legend.fontSize = 13
legend.strokeColor = None
if 'x' in kwargs:
legend.x = kwargs['x']
if 'y' in kwargs:
legend.y = kwargs['y']
legend.alignment = 'right'
if 'boxAnchor' in kwargs:
legend.boxAnchor = kwargs['boxAnchor']
if 'columnMaximum' in kwargs:
legend.columnMaximum = kwargs['columnMaximum']
# x-distance between neighbouring swatche\s
legend.deltax = 0
lcolors = legendcolors
if chart_type == 'line':
lcolors = [colors.red, colors.blue]
legend.colorNamePairs = zip(lcolors, labels)
for i, color in enumerate(lcolors):
if chart_type == 'line':
chart.lines[i].fillColor = color
elif chart_type == 'pie':
chart.slices[i].fillColor = color
elif chart_type == 'bar':
chart.bars[i].fillColor = color
return legend
示例4: __add_graph
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [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: setLegend
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
def setLegend(self):
legend = Legend()
legend.colorNamePairs = []
legend.fontName = 'Helvetica-Bold'
legend.fontSize = 12
legend.x = 100
legend.y = 110
legend.dxTextSpace = 5
legend.dy = 20
legend.dx = 20
legend.deltay = 5
legend.deltax = 7
legend.columnMaximum = 1
legend.alignment ='right'
legend.x = 60
legend.y = 50
legend.columnMaximum = 2
legend.colorNamePairs = []
legend.colorNamePairs.append((colors.green,
self._data_dict['max_score_legend']))
legend.colorNamePairs.append((colors.red,
self._data_dict['score_legend']))
self.add(legend, name='Legend')
示例6: myBarLegend
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
def myBarLegend(drawing, name1, name2):
"Add sample swatches to a diagram."
d = drawing or Drawing(400, 200)
swatches = Legend()
swatches.alignment = 'right'
swatches.x = 80
swatches.y = 160
swatches.deltax = 60
swatches.dxTextSpace = 10
swatches.columnMaximum = 4
items = [(colors.blue, name1), (colors.lightblue, name2)]
swatches.colorNamePairs = items
d.add(swatches, 'legend')
return d
示例7: sample3
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
def sample3(drawing=None):
"Add sample swatches to a diagram."
d = drawing or Drawing(400, 200)
swatches = Legend()
swatches.alignment = 'right'
swatches.x = 80
swatches.y = 160
swatches.deltax = 60
swatches.dxTextSpace = 10
swatches.columnMaximum = 4
items = [(colors.red, 'before'), (colors.green, 'after')]
swatches.colorNamePairs = items
d.add(swatches, 'legend')
return d
示例8: __get_tags_statistics
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
def __get_tags_statistics(self):
monto_categorias = dict()
for tra in self.transactions:
if len(tra.tags) > 0:
for tag in tra.tags:
if tag in monto_categorias.keys():
monto_categorias[tag] += tra.amount
else:
monto_categorias[tag] = tra.amount
labels = [lab.encode('utf-8') for lab in monto_categorias.keys()]
data = monto_categorias.values()
p = PageBreak()
p.drawOn(self.c, 0, 1000)
self.c.showPage()
self.l = 600
self.c.setFont('Courier', 14)
self.c.drawString(30, 800, 'Categorias')
drawing = Drawing(200, 200)
pie = Pie()
pie.x = 30
pie.y = self.l - 130
pie.height = 300
pie.width = 300
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 = self.l
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, 10
renderPDF.draw(drawing, self.c, x, y, showBoundary=False)
示例9: create_single_grade_pdf
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
#.........这里部分代码省略.........
#Y-axis min, max, and steps.
if minimum != 100:
bc.valueAxis.valueMin = minimum -10
else:
bc.valueAxis.valueMin = 50
bc.valueAxis.valueMax = 100
bc.valueAxis.valueStep = 5
#where to anchor the origin of the graph
bc.categoryAxis.labels.boxAnchor = 'ne'
#Locations of labels for the X-axis
bc.categoryAxis.labels.dx = 2
bc.categoryAxis.labels.dy = -2
bc.barLabels.nudge = -10
bc.barLabelFormat = '%.2f%%'
bc.barLabels.dx = 0
bc.barLabels.dy = 0
#The angle of the lables for the X-axis
bc.categoryAxis.labels.angle = 30
#List of the categories to place on the X-axis
bc.categoryAxis.categoryNames = standard_ref_list
drawing.add(bc)
'''------'''
'''--Graph Legend--'''
#Graph Legend
legend = Legend()
legend.alignment = 'right'
legend.x = 420
legend.y = 150
legend.deltax = 60
legend.dxTextSpace = 10
legend.columnMaximum = 4
legend.colorNamePairs = [(colors.lightblue, 'grade average')]
drawing.add(legend, 'legend')
drawing_title = "Bar Graph"
Story.append(drawing)
Story.append(Spacer(1,15))
#LineGraph Title
ptext = '<font size=15><b>Class Performance by Assignment</b></font>'
Story.append(Paragraph(ptext, styles["title"]))
Story.append(Spacer(1,30))
'''
Line Plot Graph ------
'''
assignment_data_all =[[],[]]
for key in assignment_dict.keys():
assignment_data_all[0].append(assignment_dict[key][2])
assignment_data_all[1].append(assignment_dict[key][1])
drawing2 = Drawing(600, 200)
data2 = assignment_data_all
#lp = LinePlot()
#data[0] = preprocessData(data[0])
lp = HorizontalLineChart()
lp.x = -20
lp.y = 0
lp.height = 225
lp.width = 500
lp.data = data2
lp.joinedLines = 1
lp.lines.symbol = makeMarker('FilledCircle')
示例10: make_graphs
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
#.........这里部分代码省略.........
for key in self.framework.keys():
plot_dxdy.lines[key].strokeColor = None
plot_dxdy.lines[key].symbol = makeMarker('Circle')
plot_dxdy.lines[key].symbol.strokeColor = None
plot_dxdy.lines[key].symbol.fillColor = self.framework[key]["color"]
plot_dxdy.lines[key].symbol.size = 1.2
plot_dxdy.lines[3].strokeColor = None
plot_dxdy.lines[3].symbol = makeMarker('Circle')
plot_dxdy.lines[3].symbol.strokeColor = colors.blue
plot_dxdy.lines[3].symbol.fillColor = None
plot_dxdy.lines[3].symbol.strokeWidth = 0.6
plot_dxdy.lines[3].symbol.size = plot_dim*(self.sqrtr2)
#print plot_dxdy.lines[3].symbol.getProperties()
plot_dxdy.width = plot_dim
plot_dxdy.height = plot_dim
plot_dxdy.xValueAxis.valueMax = 1.0
plot_dxdy.xValueAxis.valueMin = -1.0
plot_dxdy.xValueAxis.joinAxis = plot_dxdy.yValueAxis
plot_dxdy.xValueAxis.joinAxisMode = 'value'
plot_dxdy.xValueAxis.joinAxisPos = -1.0
plot_dxdy.yValueAxis.valueMax = 1.0
plot_dxdy.yValueAxis.valueMin = -1.0
d_dxdy = Drawing(plot_dim,plot_dim)
d_dxdy.add(plot_dxdy)
# construct cdf plot
plot_cdf_pos = (left_margin*inch, height - 2.0*(plot_dim + 0.5*inch))
plot_cdf = LinePlot()
plot_cdf.data = self.plot_cdf_data
plot_cdf.lines[0].strokeColor = colors.blue
for key in std_colors.keys():
plot_cdf.lines[key+1].strokeColor = None
plot_cdf.lines[key+1].symbol = makeMarker('Circle')
plot_cdf.lines[key+1].symbol.strokeColor = None
plot_cdf.lines[key+1].symbol.fillColor = std_colors[key]
plot_cdf.lines[key+1].symbol.size = 1.2
if (len(self.plot_cdf_data) == 5):
plot_cdf.lines[4].strokeColor = colors.green
plot_cdf.width = plot_dim
plot_cdf.height = plot_dim
plot_cdf.xValueAxis.valueMax = 1.0
plot_cdf.xValueAxis.valueMin = 0.0
plot_cdf.yValueAxis.valueMax = 1.0
plot_cdf.yValueAxis.valueMin = 0.0
d_cdf = Drawing(plot_dim,plot_dim)
d_cdf.add(plot_cdf)
# construct pdf plot
plot_pdf_pos = (left_margin*inch, height - 3.0*(plot_dim + 0.5*inch))
plot_pdf = LinePlot()
plot_pdf.data = self.plot_pdf_data
plot_pdf.lines[1].strokeColor = colors.blue
plot_pdf.lines[0].strokeColor = None
plot_pdf.lines[0].symbol = makeMarker('Circle')
plot_pdf.lines[0].symbol.strokeColor = colors.red
plot_pdf.lines[0].symbol.size = 1
plot_pdf.width = plot_dim
plot_pdf.height = plot_dim
plot_pdf.xValueAxis.valueMax = 1.0
plot_pdf.xValueAxis.valueMin = 0.0
d_pdf = Drawing(2*plot_dim,plot_dim)
d_pdf.add(plot_pdf)
# add legend
legend = Legend()
legend.alignment = 'right'
legend.colorNamePairs = [(std_colors[0],'Inliers (%d'%int(self.fraction*100.0) + '% used for fit)'),
(std_colors[1],'Other inliers'),
(std_colors[2],'Outliers, reject next round'),]
for key in self.framework.keys():
legend.colorNamePairs.append( (self.framework[key]["color"], "%s"%self.framework[key]["status"] ) )
legend.x = plot_dim - 1.0*inch
legend.y = plot_dim
legend.columnMaximum = 8
d_pdf.add(legend)
# add titles
title_pos = (plot_dim/2.0,plot_dim + 0.25*inch)
title_dxdy = String(title_pos[0],title_pos[1],'dx vs. dy (all)')
title_dxdy.fontSize = 15
title_dxdy.textAnchor = 'middle'
d_dxdy.add(title_dxdy)
title_cdf = String(title_pos[0],title_pos[1],'cdf (good)')
title_cdf.fontSize = 15
title_cdf.textAnchor = 'middle'
d_cdf.add(title_cdf)
title_pdf = String(title_pos[0],title_pos[1],'pdf (good)')
title_pdf.fontSize = 15
title_pdf.textAnchor = 'middle'
d_pdf.add(title_pdf)
# draw everything
renderPDF.draw(d_dxdy,canvas,plot_dxdy_pos[0],plot_dxdy_pos[1])
renderPDF.draw(d_cdf,canvas,plot_cdf_pos[0],plot_cdf_pos[1])
renderPDF.draw(d_pdf,canvas,plot_pdf_pos[0],plot_pdf_pos[1])
示例11: run
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
#.........这里部分代码省略.........
# Lookup the integer weight of this answer
if value in answeroptions:
index = answeroptions.index(value)
weight = weights[index]
# Always add to the list. ReportLab deals with None.
if counter == 0:
dimension_one_values.append(weight)
else:
dimension_two_values.append(weight)
counter += 1
# Set minmax
absmax = max(abs(minval), abs(maxval)) * 1.1
lc.xValueAxis.valueMin = -absmax
lc.xValueAxis.valueMax = absmax
lc.yValueAxis.valueMin = -absmax
lc.yValueAxis.valueMax = absmax
# Zip to create data
data = [zip(dimension_one_values, dimension_two_values)]
if not len(data[0]):
return
lc.x = 0
lc.y = 0
# Misc setup
lc.height = 300
lc.width = 300
lc.data = data
lc.joinedLines = 0
lc.fillColor = None
lc.lines[0].strokeColor = colors.red
lc.lines[0].symbol = makeMarker('FilledCircle')
# Add a grid
grid = DoubleGrid()
lc.background = grid
setupGrid(lc)
lc.background = None
# Finetune the grid
grid.grid0.strokeWidth = 0.2
grid.grid1.strokeWidth = 0.2
# Add to drawing else it overwrites the center Y axis
drawing.add(grid)
# Add a Y axis to pass through the origin
yaxis = YValueAxis()
yaxis.setPosition(lc.width/2, 0, lc.height)
yaxis.configure([(0,-absmax),(0,absmax)])
yaxis.strokeColor = colors.blue
drawing.add(yaxis)
# Color X-Axis
lc.xValueAxis.strokeColor = colors.green
drawing.add(lc)
# Legend for Dimension One
drawing.add(String(lc.width+20, lc.height-12, 'Dimension One (X-Axis):',
fontName='Helvetica', fontSize=12, fillColor=colors.green))
legend = Legend()
legend.alignment = 'right'
legend.x = lc.width + 20
legend.y = lc.height - 20
legend.fontName = 'Helvetica'
legend.fontSize = 12
legend.columnMaximum = 7
items = []
for ob in dimension_one_answeroptions_as_objects:
items.append( ( StringWidget(ob.getWeight()), ob() ) )
legend.colorNamePairs = items
drawing.add(legend, 'legend1')
# Legend for Dimension Two
drawing.add(String(lc.width+20, lc.height/2-12, 'Dimension Two (Y-Axis):',
fontName='Helvetica', fontSize=12, fillColor=colors.blue))
legend = Legend()
legend.alignment = 'right'
legend.x = lc.width + 20
legend.y = lc.height/2 - 20
legend.fontName = 'Helvetica'
legend.fontSize = 12
legend.columnMaximum = 7
items = []
for ob in dimension_two_answeroptions_as_objects:
items.append( ( StringWidget(ob.getWeight()), ob() ) )
legend.colorNamePairs = items
drawing.add(legend, 'legend2')
# Write out
data = drawing.asString('png')
request = self.REQUEST
response = request.RESPONSE
response.setHeader('Content-Type', 'image/png')
response.setHeader('Content-Disposition','inline; filename=%s.png' % self.getId())
response.setHeader('Content-Length', len(data))
response.setHeader('Cache-Control', 's-maxage=0')
return data
示例12: generar_pdf_busquedas_view
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
#.........这里部分代码省略.........
bc.categoryAxis.labels.dy = -2
bc.categoryAxis.labels.angle = 0
bc.categoryAxis.categoryNames = ['Encontradas', 'No Encontradas']
drawing.add(bc)
bc.barLabels.nudge = 20
bc.barLabelFormat = '%0.0f'
bc.barLabels.dx = 0
bc.barLabels.dy = 0
bc.barLabels.boxAnchor = 'n' # irrelevant (becomes 'c')
bc.barLabels.fontName = 'Helvetica'
bc.barLabels.fontSize = 14
#GRAFICAS DE PASTEL
titulo2 = Paragraph("Busquedas y número de veces realizadas", estilo['title'])
d = Drawing(400, 200)
pc = Pie()
pc.x = 125
pc.y = 25
pc.data = lista
print lista
#pc.data = [7, 1, 1, 1, 1, 2]
#pc.labels = [ str(i.values()) for i in Busqueda.objects.filter(fecha__range=(fecha_inicio, fecha_final)).values('busqueda').distinct()]
lista_labels = [ str(i.values()) for i in Busqueda.objects.filter(fecha__range=(fecha_inicio, fecha_final)).values('busqueda').distinct()]
#pc.labels = ['example1', 'example2', 'example3', 'example4', 'example5', 'example6']
pc.sideLabels = 1
pc.width = 150
pc.height = 150
pc.slices.strokeWidth=1#0.5
pc.slices[0].fillColor = colors.yellow
pc.slices[1].fillColor = colors.thistle
pc.slices[2].fillColor = colors.cornflower
pc.slices[3].fillColor = colors.lightsteelblue
pc.slices[4].fillColor = colors.aquamarine
pc.slices[5].fillColor = colors.cadetblue
d.add(pc)
legend = Legend()
legend.x = 370
legend.y = 0
legend.dx = 10
legend.dy = 10
legend.fontName = 'Helvetica'
legend.fontSize = 10
legend.boxAnchor = 'n'
legend.columnMaximum = 10
legend.strokeWidth = 1
legend.strokeColor = colors.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
#Insertemos nuestros propios colores
colores = [colors.blue, colors.red, colors.green, colors.yellow, colors.black, colors.white, colors.silver, colors.pink, colors.brown, colors.orange, colors.purple]
for i, color in enumerate(colores):
pc.slices[i].fillColor = color
legend.colorNamePairs = [(
pc.slices[i].fillColor,
(lista_labels[i][0:200], '%0.0f' % pc.data[i])
) for i in xrange(len(pc.data))]
d.add(pc)
reportes.append(t)
reportes.append(Spacer(0, inch*.1))
reportes.append(Spacer(0, inch*.1))
reportes.append(Spacer(0, inch*.1))
reportes.append(titulo)
reportes.append(drawing)
reportes.append(Spacer(0, inch*.1))
reportes.append(Spacer(0, inch*.1))
reportes.append(titulo2)
d.add(legend)
reportes.append(d)
doc.build(reportes)
response.write(buff.getvalue())
buff.close()
return response
示例13: __per_account_statistic
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
def __per_account_statistic(self):
for acc in self.accounts:
p = PageBreak()
p.drawOn(self.c, 0, 1000)
self.c.showPage()
self.l = 760
self.c.setFont('Courier', 14)
self.c.drawString(30, 800, 'Cuenta: %s' % \
acc.name)
header = ['Fecha', 'Tipo', 'Monto', 'Description']
data = [header]
g_data = list()
g_labe = list()
total = 0
for tra in self.transactions:
if tra.account == acc.name:
if tra.t_type in ['expense', 'transfer']:
tipo = self.__translate_type(tra.t_type)
data.append([tra.date, tipo.upper(),
'$%2.f' % tra.amount, tra.description])
total += tra.amount
g_data.append(tra.amount)
g_labe.append(tra.description.encode('utf-8'))
data.append(['TOTAL', '', '$%.2f' % total, ''])
if len(g_data) == 0 or len(g_labe) == 0:
self.c.setFont('Courier', 12)
self.c.drawString(30, 770, 'Sin movimientos negativos')
continue
from_title = 35
if len(data) != 2:
self.l -= ((len(data) * len(data)) + len(data)) + from_title
t = Table(data)
t.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.25, black),
('BOX', (0,0), (-1,-1), 0.25, black),
('FONTNAME', (0,0), (-1,0), 'Courier-Bold'),
('BACKGROUND', (0,0), (-1,0), HexColor('#efeded')),
('BACKGROUND', (0,0), (0,-1), HexColor('#efeded')),
('FONTSIZE', (0,0), (-1,0), 12),
('FONTSIZE', (0,1), (-1,-1), 8),
('FONTNAME', (0,1), (-1,-1), 'Courier'),
('BACKGROUND', (0,-1), (-1,-1), red),
('TEXTCOLOR', (0,-1), (-1,-1), white)]))
t.wrapOn(self.c, 30, self.l)
t.drawOn(self.c, 30, self.l)
drawing = Drawing(200, 100)
pie = Pie()
pie.x = 30
pie.y = self.l - 300
pie.height = 200
pie.width = 200
pie.data = g_data
pie.labels = g_labe
pie.simpleLabels = 1
pie.slices.strokeWidth = 1
pie.slices.strokeColor = black
pie.slices.label_visible = 0
pie.slices.popout = 1
#pie.labels = map(str, pie.data)
legend = Legend()
legend.x = 250
legend.y = self.l - 250
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)]
#.........这里部分代码省略.........
示例14: Drawing
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
renderPDF.draw(chartCanvas, c, 50, 400)
pieChartCanvas = Drawing()
pieChart = Pie()
pieChart.data = [30.0, 21.0, 21.0, 14.0, 14.0]
pieChart.slices[0].fillColor = PCMYKColor(100,0,90,50,alpha=85)
pieChart.slices[1].fillColor = PCMYKColor(0,100,100,40,alpha=85)
pieChart.slices[2].fillColor = PCMYKColor(100,60,0,50,alpha=85)
pieChart.slices[3].fillColor = PCMYKColor(23,51,0,4,alpha=85)
pieChart.slices[4].fillColor = PCMYKColor(66,13,0,22,alpha=85)
pieChart.width = 100
pieChart.height = 100
pieChart.slices.popout = 5
pieChart.slices.strokeColor = PCMYKColor(0,0,0,0)
pieChart.slices.strokeWidth = 0.5
pieChartCanvas.add(pieChart)
renderPDF.draw(pieChartCanvas, c, 100, 100)
pieChartLegendCanvas = Drawing()
pieChartLegend = Legend()
pieChartLegend.x = 100
pieChartLegend.y = 100
pieChartLegend.alignment = "right"
pieChartLegend.columnMaximum = 5
pieChartLegend.colorNamePairs = [(PCMYKColor(100,0,90,50,alpha=100), ('BP', '30%')), (PCMYKColor(0,100,100,40,alpha=100), ('Shell Transport & Trading', '21%')), (PCMYKColor(100,60,0,50,alpha=100), ('Liberty International', '21%')), (PCMYKColor(23,51,0,4,alpha=100), ('Persimmon', '14%')), (PCMYKColor(66,13,0,22,alpha=100), ('Royal Bank of Scotland', '14%'))]
pieChartLegendCanvas.add(pieChartLegend)
renderPDF.draw(pieChartLegendCanvas, c, 100, 100)
c.showPage()
c.save()
示例15: create_single_grade_pdf
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import columnMaximum [as 别名]
#.........这里部分代码省略.........
#Setup the Dictionary of standard averages
standard_dict = {}
for row in standard_list:
if row.standard.id in standard_dict.keys():
if((row.grade.score != 0.0) | (row.student_grade.student_score != 0.0)):
max_score = standard_dict[row.standard.id][0] + row.grade.score
student_score = standard_dict[row.standard.id][1] + row.student_grade.student_score
standard_dict[row.standard.id] = [max_score, student_score, row.standard.reference_number, row.standard.short_name]
else:
standard_dict[row.standard.id] = [row.grade.score, row.student_grade.student_score, row.standard.reference_number, row.standard.short_name]
standard_table = []
standard_averages=[[]]
#set up the 2D list of Standard Averages
for standard in sorted(standard_dict.keys()):
standard_ref_list.append(standard_dict[standard][2])
standard_table.append([])
current_avg = (standard_dict[standard][1]/standard_dict[standard][0])*100
if minimum > current_avg:
minimum = current_avg
standard_table[i].append(standard_dict[standard][3]+": "+format((standard_dict[standard][1]/standard_dict[standard][0])*100,'.2f')+"%")
standard_averages[0].append(int(round((standard_dict[standard][1]/standard_dict[standard][0])*100)))
i+=1
sorted(standard_table,key=lambda l:l[0])
'''---Graph---'''
drawing = Drawing(600, 200)
data = standard_averages
bc = VerticalBarChart()
#location in the document (x,y)
bc.x = 10
bc.y = 30
#width and height of the graph
bc.height = 225
bc.width = 400
bc.data = data
bc.categoryAxis.drawGridLast=True
bc.categoryAxis.gridStart=0
bc.categoryAxis.gridStrokeLineCap = 2
bc.categoryAxis.gridEnd=3
#bc.barLabels =
#Update colors of the bars in the graph
bc.bars.symbol = ShadedRect()
bc.bars.symbol.fillColorStart = colors.lightblue
bc.bars.symbol.fillColorEnd = colors.lightblue
bc.bars.symbol.strokeWidth = 0
#this draws a line at the top of the graph to close it.
bc.strokeColor = colors.black
#Y-axis min, max, and steps.
if minimum != 100:
bc.valueAxis.valueMin = minimum -10
else:
bc.valueAxis.valueMin = 50
bc.valueAxis.valueMax = 100
bc.valueAxis.valueStep = 5
#where to anchor the origin of the graph
bc.categoryAxis.labels.boxAnchor = 'ne'
#Locations of labels for the X-axis
bc.categoryAxis.labels.dx = 2
bc.categoryAxis.labels.dy = -2
bc.barLabels.nudge = -10
bc.barLabelFormat = '%0.2f%%'
bc.barLabels.dx = 0
bc.barLabels.dy = 0
#The angle of the lables for the X-axis
bc.categoryAxis.labels.angle = 30
#List of the categories to place on the X-axis
bc.categoryAxis.categoryNames = standard_ref_list
drawing.add(bc)
'''------'''
'''--Graph Legend--'''
#Graph Legend
legend = Legend()
legend.alignment = 'right'
legend.x = 420
legend.y = 150
legend.deltax = 60
legend.dxTextSpace = 10
legend.columnMaximum = 4
legend.colorNamePairs = [(colors.lightblue, 'grade average')]
drawing.add(legend, 'legend')
drawing_title = "Bar Graph"
Story.append(drawing)
#build PDF document and return it
doc.build(Story)
pdf = buff.getvalue()
buff.close()
return pdf