[reportlab-users] Graphics and titles

Andy Robinson andy at reportlab.com
Tue Jul 5 07:43:57 EDT 2005


JP Glutting wrote:
> Just a question to see if anyone has any ideas. I use a lot of line 
> charts and bar charts, and, as far as I can tell from looking at the 
> code, there is no way to make the title of the chart part of the Drawing 
> image. Maybe I missed something.
> 
> So, what I have been doing is printing out the title, and then putting 
> the graphic right after it. That is fine if I keep close control of what 
> goes on a page, but right now I have a very long series of charts I want 
> to generate automatically (survey questions and their responses). The 
> method of printing the title and then printing the graphic often results 
> in the survey question being printed at the end of one page, and the 
> graphic at the head of the next one. If I could insert the title into 
> the graphic, they would stay together, and that would be the best solution.
> 
> Failing that, does anyone have any good ideas about how to keep the two 
> elements on the same page?

You can add any number of objects to a Drawing - titles, legends, charts
etc.  Just add a String node and call it title e.g.

	d = Drawing()
	vbc = VerticalBarChart()

	#add it to the drawing.
	d.add(vbc, name='chart')
         #now refer to it...
	d.chart.x = 50

	#add a String object as the title
	d.add(String(180,180, "Profits for February"), name="title")
   	#now customize it further
	d.title.fontName = 'Helvetica-Bold'


Hope this helps,


Andy Robinson




More information about the reportlab-users mailing list