[reportlab-users] graphics/charts background images

Robin Becker reportlab-users@reportlab.com
Sat, 27 Jul 2002 15:55:57 +0100


In article <3D42AD3C.330B26A7@rasselstein-hoesch.de>, Dirk Datzert <dirk.datzert@tks-
rasselstein.thyssenkrupp.com> writes
>Hi,
>
>is it possible to put images or ShadedRect into the background of
>barcharts or linecharts ?
>
>Regards,
>Dirk
....
ShadedRect's etc can certainly be used below a chart. The trouble is there's no real concept of
background for a chart ie we don't seem to have the traditional chartarea, plot area etc etc.

Certainly Drawings have a background attribute, which can be set to ShadedRects/flags etc, but
we still need to set the size.


import reportlab
from reportlab.graphics.widgets.grids import ShadedRect
from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin
from reportlab.lib.colors import maroon, lime, coral, lightgreen, ReportLabBlue, purple,
lightgrey, pink, lightblue, yellow

class Drawing_003(_DrawingEditorMixin,Drawing):
        def __init__(self,width=400,height=200,*args,**kw):
                apply(Drawing.__init__,(self,width,height)+args,kw)
                self.add(reportlab.graphics.charts.barcharts.HorizontalBarChart(),name='chart')
                self.chart.y=20
                self.chart.width=self.width-self.chart.x-10
                self.chart.height=self.height-self.chart.y-10
                self.chart.data  = [(100,110,120,130,80,80,60,55,23,200,110,210)]
                self.chart.valueAxis.rangeRound='both'
                self.chart.bars[2].fillColor = pink
                self.chart.bars[3].fillColor = maroon
                self.chart.bars[4].fillColor = lime
                self.chart.bars[5].fillColor = yellow
                self.chart.bars[6].fillColor = lightblue
                self.chart.bars[7].fillColor = coral
                self.chart.bars[8].fillColor = lightgreen
                self.chart.bars[9].fillColor = ReportLabBlue
                self.chart.bars[10].fillColor = purple
                self.chart.bars[11].fillColor = lightgrey
                self.chart.bars[(0,5)].fillColor  = yellow
                self.chart.bars[(0, 6)].fillColor = pink
                self.chart.bars[0, 7].fillColor = ReportLabBlue
                self.background = ShadedRect()
                self.background.width          = self.width
                self.background.height         = self.height

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

 
-- 
Robin Becker