Django ReportLab

0

Good I have the following doubt I am doing a function to return a pdf with a graph I am doing with ReportLab my question is the following as I indicate to the canvas that I paint my graph and return it in the pdf generated now it returns the pdf in white here I leave my code

response            = HttpResponse(content_type='application/pdf')
nombre_pdf          = oficina + piso
nombre_pdf          = get_valid_filename(nombre_pdf)
response['Content-Disposition']         = 'attachment; filename=' + nombre_pdf

buffer = BytesIO ()     p = canvas.Canvas (buffer)

from reportlab.lib.colors import PCMYKColor
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart

d = Drawing(280, 250)
bar = VerticalBarChart()
bar.x = 50
bar.y = 85
data = [[1,2,3,None,None,None,5],
        [10,5,2,6,8,3,5],
        [5,7,2,8,8,2,5],
        [2,10,2,1,8,9,5],
        ]
bar.data = data
bar.categoryAxis.categoryNames = ['Year1', 'Year2', 'Year3',
                                  'Year4', 'Year5', 'Year6',
                                  'Year7']

bar.bars[0].fillColor   = PCMYKColor(0,100,100,40,alpha=85)
bar.bars[1].fillColor   = PCMYKColor(23,51,0,4,alpha=85)
bar.bars.fillColor       = PCMYKColor(100,0,90,50,alpha=85)

d.add(bar, '')
    
asked by David Gomez García 21.09.2017 в 17:17
source

1 answer

0

Well the truth is I do not know how to use the code as such to generate the pdf, but there is something called wrap (parameter1, parameter2) that receives two parameters, width and height respectively, these parameters are what define the space in the that the graph be painted on the document, then the drawOn method is placed (canvas, Parameter1, Parameter2), the latter is the one that paints the graph, receives the canvas, the position in x , and the position in and that would be enough to show you the graphic ...

I hope my answer will be useful to you and I also hope that I have made the right decision in the way you use reportlab ... greetings ...

    
answered by 27.10.2017 в 23:13