[reportlab-users] two data -aware diagrams in one pdf

Soumya Mishra mishras at vmware.com
Tue Jul 5 17:56:54 EDT 2011


Hi,
I am trying to make a single pdf with 2 data aware diagrams. One is a bar chart which is taking data from table 1 and other is string (text box kind of thing) which gets its data from another table. When I run this program in reportlab, the string part(class which has the code for connecting string to database and displaying it) which is called later overwrites the bar chart diagram. I am not finding any way to display both of them together in one pdf. Please suggest.

from rlextra.graphics.guiedit.datacharts import DataAwareDrawing, ODBCDataSource, DataAssociation
from reportlab.graphics.charts.barcharts import VerticalBarChart3D
from reportlab.graphics.shapes import _DrawingEditorMixin, Line, String
from reportlab.lib.colors import red
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
import time
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch



class avg_max_min(_DrawingEditorMixin,DataAwareDrawing):
def __init__(self,width=1000,height=1000,*args,**kw):
DataAwareDrawing.__init__(self,width,height,*args,**kw)
self._add(self,Line(750,900,900,900),name='horline1',validate=None,desc=None)
self._add(self,Line(750,930,900,930),name='horline2',validate=None,desc=None)
self._add(self,Line(750,960,900,960),name='horline3',validate=None,desc=None)
self._add(self,Line(750,900,750,960),name='verline1',validate=None,desc=None)
self._add(self,Line(800,900,800,960),name='verline2',validate=None,desc=None)
self._add(self,Line(850,900,850,960),name='verline3',validate=None,desc=None)
self._add(self,Line(900,900,900,960),name='verline4',validate=None,desc=None)
self._add(self,String(760,945,'Average'),name='label1',validate=None,desc=None)
self.label1.fontSize = 8
self.label1.fillColor = red
self.label1.textAnchor = 'start'
self._add(self,String(810,945,'Minimum'),name='label2',validate=None,desc=None)
self.label2.fillColor = red
self.label2.fontSize = 8
self.label2.textAnchor = 'start'
self._add(self,String(860,945,'Maximum'),name='label3',validate=None,desc=None)
self.label3.fillColor = red
self.label3.fontSize = 8
self.label2.textAnchor = 'start'
self._add(self,String(760,915,'text'),name='label4',validate=None,desc=None)
self._add(self,String(810,915,'text'),name='label5',validate=None,desc=None)
self._add(self,String(860,915,'text'),name='label6',validate=None,desc=None)
self.dataSource = ODBCDataSource()
self.dataSource.driver = 'mysql'
self.dataSource.name = 'view'
self.dataSource.user = 'root'
self.dataSource.password = 'soumya'
self.dataSource.sql = 'select cast(avg(diff) as char(50)), cast(min(diff) as char(50)),cast(max(diff) as char(50)) from new_table'
self.dataSource.associations.size = 3
self.dataSource.associations.element00 = DataAssociation(column=0, target='label4.text', assocType='scalar')
self.dataSource.associations.element01 = DataAssociation(column=1, target='label5.text', assocType='scalar')
self.dataSource.associations.element02 = DataAssociation(column=2, target='label6.text', assocType='scalar')



class final_logon(_DrawingEditorMixin,DataAwareDrawing):
def __init__(self,width=1000,height=1000,*args,**kw):
DataAwareDrawing.__init__(self,width,height,*args,**kw)
self._add(self,VerticalBarChart3D(),name='vertical',validate=None,desc=None)
self.vertical.x = 150
self.vertical.y = 200
self.vertical.width = 600
self.vertical.height = 600
self.dataSource = ODBCDataSource()
self.dataSource.driver = 'mysql'
self.dataSource.name = 'view'
self.dataSource.user = 'root'
self.dataSource.password = 'soumya'
self.dataSource.sql = 'select id, range_value, user_number from final_logon'
self.dataSource.associations.size = 3
self.dataSource.associations.element00 = DataAssociation(column=0, target='verticalId', assocType='scalar')
self.dataSource.associations.element02 = DataAssociation(column=1, target='vertical.categoryAxis.categoryNames', assocType='vector')
self.dataSource.associations.element01 = DataAssociation(column=2, target='vertical.data', assocType='tmatrix')


doc = SimpleDocTemplate("merged.pdf",pagesize=letter,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
Story = []
Story.append(avg_max_min().go())
Story.append(final_logon().go())
doc.build(Story)

Error which I am getting:
C:\Python26\to be merged>merged.py
Traceback (most recent call last):
File "C:\Python26\to be merged\merged.py", line 96, in <module>
doc.build(Story)
File "C:\Python26\lib\site-packages\reportlab\platypus\doctemplate.py", line 1
117, in build
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
File "C:\Python26\lib\site-packages\reportlab\platypus\doctemplate.py", line 8
80, in build
self.handle_flowable(flowables)
File "C:\Python26\lib\site-packages\reportlab\platypus\doctemplate.py", line 7
44, in handle_flowable
self.handle_keepWithNext(flowables)
File "C:\Python26\lib\site-packages\reportlab\platypus\doctemplate.py", line 7
11, in handle_keepWithNext
while i<n and flowables[i].getKeepWithNext(): i += 1
AttributeError: 'NoneType' object has no attribute 'getKeepWithNext'

Thanks,
Soumya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20110705/4896d5c1/attachment-0001.html>


More information about the reportlab-users mailing list