[reportlab-users] Computing chart size

Johan Paul Glutting reportlab-users@reportlab.com
Mon, 04 Oct 2004 17:11:57 +0200

Sorry, these are the relevant imports:

from reportlab.graphics.charts.textlabels import Label
from reportlab.graphics.charts.legends import Legend, LineLegend
from reportlab.graphics.charts.linecharts import HorizontalLineChart, 
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.widgets.markers import makeMarker
from reportlab.graphics.widgets.grids import ShadedRect

that will also tell you which modules containt the relevant functions.

I see what you mean about the width. I don't have that problem, since I 
am doing five-year periods and I have horizontal space to spare. My 
vertical axis does change a lot - I have two charts from my development 
dataset, and they range from 0-400 and 0-3000, respectively. I just let 
them compress or not. You would probably have to do some calculations 
based on your data to adjust the width, based on the length of your 
inner sequences (for example, len(data[0]) ). I don't know if there is 
an easy way to determine the size of the drawing you need. I had to do 
some simple calculations to leave space for the legend at the bottom, so 
you should be able to determine the ammount of horizontal space (in 
pixels) that you want to devote to each category, and multiply by the 
number of categories to get the horizontal width of the chart (and the 
drawing, since I don't think you need to have a buvver, unless you want 
a border). Add a little for the labels on the Y axis. Not sure how much, 
you will have to try that yourself. The first thing might be to 
calculate the largest drawing that will fit on your page, and then work 
down from there, subtract what you need for the labels, and then the 
rest of the space is used by the graph...

This all assumes that the legend goes under the graph (like mine) and 
not on the side ...



En/na Vladimir Prus ha escrit:

>Hi Johan,
>>You can try this function I am using to generate graphs. It just uses a
>>fixed size (which is probably what you want, since your page is always
>>going to be the same size), but you can pass in the size you want
>>specifically. It has some settings that are what I want for all my
>>charts, and these cannot be changed (like the filled diamond, but you
>>could pass that in as well).
>Thanks, I like the result it produces. I've some questions, however:
>1. Since the width is fixed, if I put more data, the data points are placed 
>more closely. Is it possible to specify the spacing between data points, and 
>compute the needed width of the image.
>2. You use LineLegend, but my copy of sources have only "Legend". Is 
>LineLegend a recent addition?
>3. Where is 'makeMarker' defined?
>reportlab-users mailing list

JP Glutting
Oficina de Qualitat		Plaša VÝctor Siurana, 1
Universitat de Lleida		25003 Lleida
Tel: 973 703 103		Fax: 973 702 036