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

Robin Becker robin at reportlab.com
Wed Jul 6 05:00:43 EDT 2011


On 05/07/2011 22:56, Soumya Mishra wrote:

> 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.

>

.........

> topMargin=72,bottomMargin=18)

> Story = []

> Story.append(avg_max_min().go())

> Story.append(final_logon().go())


the problem is here; the go method is supposed to work over its data and create
multiple drawings on disk; it does not create flowables. It is a method and not
a function so each of these appends adds a None to the story.

It's not exactly obvious why you want to use DataAware drawing as a base; is the
intent to have multiple versions of these charts in each pdf (ie dependent on
how many data sets are present) or are you catually just trying to get one
drawing per pdf from each class?

Unfortunately as it stands the datacharts.py module was written a while ago so
ther isn't an obvious refactoring that would expose the charts one at a time.
The go method looks schematically a bit like this

self._getAndApplyConfig()
dsrc = self.dataSource
r = 0
dsrc.connect(verbose=verbose)
while 1:
r += 1
dataset=self.fetch
fetched = dsrc.fetchNextDataSet()
if not fetched: break
utf8data = self.normalizeEncoding(fetched)
self.applyDataSet(utf8data)
self._saveHook(verbose=self._verbose,seqNumber=r)

dsrc.close()

and the default _savehook looks like this
def _saveHook(self,**kwds):
self.save(**kwds)

so it just saves self (ie writes to disk). It should be relatively easy to
convert the above to return a number of independent flowables. However, there
are catches like don't return self multiple times and beware deepcopying self as
that will fail because of the datasource socket.




> doc.build(Story)

>

.........

> Soumya

........

--
Robin Becker


More information about the reportlab-users mailing list