[reportlab-users] pdfgen and Charts
Robin Becker
robin at reportlab.com
Fri Apr 17 10:16:57 EDT 2009
Peter Mott wrote:
> I'm using the basic pdfgen package for my project. I'd like - though it
> is not vital - to create a chart and add it to my canvas. I can add a
> path p I have created by canvas.drawPath(p) and a textobject t by
> canvas.drawText(t). I can create a rectangle r from the graphics package
> - but cannot find out how to add it to the canvas. Can this be done?
>
> Seems a silly question - but I am new to ReportLab and Googlinf all over
> has not helped!
>
> Thanks,
>
> Peter
.......
The canvas already has rectangle/circle etc etc as primitives.
The relationship of the graphics classes to the standard canvas is a bit strange.
Graphics Drawings are made up of primitive shapes as defined in the shapes.py
module. A drawing is also a flowable so it can be included fairly directly into
a platypus story.
There are chart classes already which can be made into drawings fairly easily.
If you find a chart that you like; add to a drawing and you have something that
fits easily into a story. It's a bit harder to make flowables draw themselves
onto a canvas, but usually you need to use the wrapOn and drawOn methods to do
that using code like this...
f=Chart(....)
w,h = f.wrapOn(canv,availWidth,availHeight)
f.drawOn(canv,x,y)
If you just wish to draw a simple line chart etc etc then the canvas primitives
should allow you to do it.
--
Robin Becker
More information about the reportlab-users
mailing list