I've the following code where I'm generatingdrawing a report having Pie Chartvertical bar graph and a line graph as well inside a PDF.
How do I save these 2 graphs in 2 different pages of the PDF. I saw that it can be done using -
c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()
But, instead of using Canvas, I'm using Drawing object in which showPage() method does not exist.
How do I referredsave the 2 graphs in 2 different pages of the PDF? Right the second graph(line chart) overlaps the first graph this link for(vertical bar chart), thereby hindering the tutorials purposebar chart.
Here is my code.code.
from reportlab.lib.pagesizes import cm, inch
from reportlab.graphics.charts.piechartsshapes import Pie Drawing
from reportlab.graphics.charts.legendsbarcharts import Legend VerticalBarChart
from reportlab.lib.colors import Color, PCMYKColor
from reportlab.graphics.shapesdrawing import= Drawing(400, _DrawingEditorMixin
def generate_report(request200):
data = MyDrawing().save[
(formats=['pdf'13,'png'] 5,outDir='.' 20,fnRoot=None) 22,
class37, MyDrawing(_DrawingEditorMixin45,Drawing): 19, 4),
def __init__(self,width=400,height=200,*args14,**kw):
6, apply(Drawing.__init__21,(self 23,width 38,height)+args 46,kw) 20, 5)
]
bc = self._add(self,PieVerticalBarChart(),name='chart',validate=None,desc=None)
self.chartbc.x = 20 50
self.chartbc.y = (self.height-self.chart.height)/2 50
self.chart.slicesbc.strokeWidth height = 1 125
self.chart.slicesbc.popout width = 1 300
self.chartbc.direction data = 'clockwise' data
self.chart#bc.width strokeColor = self.chartcolors.height black
selfbc.chartvalueAxis.startAngle valueMin = 90
self._add(self,Legend(),name='legend',validate=None,desc=None) 0
selfbc.legendvalueAxis.x valueMax = width - 20 50
selfbc.legendvalueAxis.y valueStep = 0 10
selfbc.legendcategoryAxis.labels.boxAnchor = 'se' 'ne'
selfbc.legendcategoryAxis.subCols[1]labels.align dx = 'right' 8
selfbc.chartcategoryAxis.height labels.dy = 99 -2
selfbc.chartcategoryAxis.width labels.angle = 99 30
selfbc.legendcategoryAxis.alignment categoryNames = 'right' ['Jan-99','Feb-99','Mar-99',
self'Apr-99','May-99','Jun-99','Jul-99','Aug-99']
drawing.legendadd(bc)
drawing.columnMaximum = 9 save()
from selfreportlab.legendgraphics.fontSize = 13charts.lineplots import LinePlot
# these data can be read from external sourcesreportlab.graphics.widgets.markers import makeMarker
drawing = Drawing(400, 200)
data = [
(5(1, 41), 3(2, 2), (2.5,1)
categories =, ('sale','marketing'3,'travel'3),'health' (4,'misc'5) ),
colors = [PCMYKColor(100(1,502),30 (2,x3) for x in, (502.5,402),30 (3.5,205),10 (4,6))
]
lp = LinePlot()
lp.x = 50
lp.y = 50
lp.height = 125
lp.width = self.chart300
lp.data = data
lp.joinedLines = self1
lp.chartlines[0].labels symbol = mapmakeMarker(str, self'FilledCircle')
lp.chartlines[1].data)symbol = makeMarker('Circle')
lp.lineLabelFormat = '%2.0f'
#lp.strokeColor = colors.black
lp.xValueAxis.valueMin = 0
lp.xValueAxis.valueMax = self5
lp.legendxValueAxis.colorNamePairsvalueSteps = zip(colors[1, categories)2, 2.5, 3, 4, 5]
lp.xValueAxis.labelTextFormat = '%2.1f'
lp.yValueAxis.valueMin = 0
lp.yValueAxis.valueMax = 7
lp.yValueAxis.valueSteps = for[1, i2, color3, in5, enumerate6]
drawing.add(colorslp): self
drawing.chartsave()
drawing.slices[i]save(formats=['pdf'],outDir='.fillColor = color ',fnRoot=None)
But, I'm getting an error saying Can't setFont(Times-Roman) missing the T1 files? Originally <type 'exceptions.TypeError'>: makeT1Font() argument 2 must be string, not None.
So, my first question is Why I'm getting this error. Where I'm going wrong?
My second question - Is this the standard way to create a report in Django? Is my aprroach to create the report correct?