[reportlab-users] Problem with bar chart example in graphics guide page 24

Robin Becker reportlab-users@reportlab.com
Tue, 26 Aug 2003 09:02:53 +0100


In article <4910-220038125191128113@M2W041.mail2web.com>,
waxmop@gtcinternet.com <waxmop@gtcinternet.com> writes
>Hi -
>

the default chart has 4 category names set in its __init__ and the draw
method complains when there aren't enough or too many.

I will alter so that we don't complain when that happens, but it
probably means you need to supply either empty category names or the
correct number of categories.


>I tried the example program on page 24 of the graphics guide, and got an
>error. Here's the program:
>
># copied right out of the graphics guide, page 24.
>
>from reportlab.graphics.shapes import Drawing
>from reportlab.graphics.charts.barcharts import VerticalBarChart
>from reportlab.lib import colors
>
>drawing = Drawing(400,200)
>
>data = [
>        (13, 5, 20, 22, 37, 45, 19, 4),
>        (14, 6, 21, 23, 38, 46, 20, 5)
>       ]
>
>bc = VerticalBarChart()
>bc.x = 50
>bc.y = 50
>bc.height = 125
>bc.width = 300
>bc.strokeColor = colors.black
>
>#set the range and tick marks on the y-axis
>bc.valueAxis.valueMin = 0
>bc.valueAxis.valueMax = 50
>bc.valueAxis.valueStep = 10
>
>bc.categoryAxis.labels.boxAnchor = 'ne'
>bc.categoryAxis.labels.dx = 8
>bc.categoryAxis.labels.dy = -2
>bc.categoryAxis.labels.angle = 30
>bc.categoryAxis.categoryNames = ['Jan-99', 'Feb-99', 'Mar-99',
>                                 'Apr-99', 'May-99', 'Jun-99',
>                                'Jul-99', 'Aug-99']
>
>drawing.add(bc)
>
>from reportlab.graphics import renderPDF
>renderPDF.drawToFile(drawing, 'funchart.pdf', 'Simple Bar Chart')
>
>
>---
>
>And here is the error I get:
>>>> import funchart
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "funchart.py", line 37, in ?
>    renderPDF.drawToFile(drawing, 'funchart.pdf', 'Simple Bar Chart')
>  File "c:\python23\lib\reportlab\graphics\renderPDF.py", line 276, in
>drawToFil
>e
>    draw(d, c, 0, 0, showBoundary=showBoundary)
>  File "c:\python23\lib\reportlab\graphics\renderPDF.py", line 25, in draw
>    R.draw(drawing, canvas, x, y, showBoundary=showBoundary)
>  File "c:\python23\lib\reportlab\graphics\renderPDF.py", line 54, in draw
>    self.drawNode(drawing)
>  File "c:\python23\lib\reportlab\graphics\renderPDF.py", line 75, in
>drawNode
>    self.drawNodeDispatcher(node)
>  File "c:\python23\lib\reportlab\graphics\renderbase.py", line 217, in
>drawNode
>Dispatcher
>    self.drawGroup(node)
>  File "c:\python23\lib\reportlab\graphics\renderbase.py", line 241, in
>drawGrou
>p
>    self.drawNode(node)
>  File "c:\python23\lib\reportlab\graphics\renderPDF.py", line 75, in
>drawNode
>    self.drawNodeDispatcher(node)
>  File "c:\python23\lib\reportlab\graphics\renderbase.py", line 217, in
>drawNode
>Dispatcher
>    self.drawGroup(node)
>  File "c:\python23\lib\reportlab\graphics\renderbase.py", line 234, in
>drawGrou
>p
>    node = _expandUserNode(node,canvas)
>  File "c:\python23\lib\reportlab\graphics\renderbase.py", line 155, in
>_expandU
>serNode
>    node = node.provideNode()
>  File "c:\python23\lib\reportlab\graphics\widgetbase.py", line 147, in
>provideN
>ode
>    return self.draw()
>  File "c:\python23\lib\reportlab\graphics\charts\axes.py", line 153, in
>draw
>    g.add(self.makeTickLabels())
>  File "c:\python23\lib\reportlab\graphics\charts\axes.py", line 302, in
>makeTic
>kLabels
>    assert len(self.categoryNames) == catCount, \
>AssertionError: expected 8 category names but found 4 in axis.
> categories = ['Jan-99', 'Feb-99', 'Mar-99', 'Apr-99', 'May-99', 'Jun-99',
>'Jul-
>99', 'Aug-99']
>
>
>
>I don't get it.  It says categories only has four names?  Can anyone help
>me out?
>
>--------------------------------------------------------------------
>mail2web - Check your email from the web at
>http://mail2web.com/ .
>
>
>_______________________________________________
>reportlab-users mailing list
>reportlab-users@reportlab.com
>http://two.pairlist.net/mailman/listinfo/reportlab-users
>

-- 
Robin Becker