[reportlab-users] Missing area charts

Dinu Gherman gherman at darwin.in-berlin.de
Fri May 29 11:44:39 EDT 2009


Robin Becker:


> from reportlab.graphics.shapes import Drawing

> from reportlab.graphics.charts.lineplots import AreaLinePlot

>

> class Drawing_000(Drawing):

> def __init__(self,width=400,height=200,*args,**kw):

> Drawing.__init__(*((self,width,height)+args),**kw)

> self.add(AreaLinePlot())

> self.contents[0].y = 20

> self.contents[0].width = 360

> self.contents[0].height = 170

>

> if __name__=="__main__": #NORUNTESTS

> Drawing_000().save(formats=['pdf'],outDir='.',fnRoot=None)



Thanks Robin! That makes it just slightly more clear. My version
below might be considered even more intuitive, since it also
gives a little hint about the format of the data to be passed...

It seems like the line color of the areas cannot be set indivi-
dually, buy hey, there should be always some room left for im-
provements! ;-)

Regards,

Dinu

"""
Provide a more intuitive sample for (stacked) area charts compared
to the documentation gven by ReportLab.
"""

from reportlab.lib import colors
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.lineplots import AreaLinePlot
from reportlab.graphics.widgets.markers import makeMarker

class Drawing_000(Drawing):
def __init__(self,width=400,height=200,*args,**kw):
Drawing.__init__(*((self,width,height)+args),**kw)

p = AreaLinePlot()
p.reversePlotOrder = 1
p.yValueAxis.valueMin = 0
# data format: [
# (x_i, y_i_0, y_i_1, ..., y_i_N-1),
# (...),
# ]
p.data = [(0, 1, 1), (1, 0, 1), (2, 1, 0), (3, 3, 3), (4, 1,
1)]
p.strokeColor = colors.black
p.lines[0].strokeColor = colors.red
p.lines[0].symbol = makeMarker('Circle')
p.lines[1].strokeColor = colors.blue
p.lines[1].symbol = makeMarker('Diamond')
self.add(p)

self.contents[0].y = 20
self.contents[0].width = 360
self.contents[0].height = 170

if __name__=="__main__":
Drawing_000().save(formats=['pdf'],outDir='.',fnRoot=None)

......................................................................
Follow me on Twitter: http://twitter.com/dinugherman

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090529/13d6087e/attachment.html>


More information about the reportlab-users mailing list