[reportlab-users] Fwd: reportlab-users Digest, Vol 122, Issue 10

Robin Becker robin at reportlab.com
Fri Feb 21 05:44:19 EST 2014


On 17/02/2014 09:21, Helga Peters wrote:

> Dear Robin,

>

> My excusses for not providing you with a runnable example.

> I try to be clearer.

>

> ##############################

> if __name__=='__main__':

> from reportlab.graphics.shapes import Drawing

> from reportlab.graphics.charts.barcharts import VerticalBarChart

> from reportlab.graphics.charts.linecharts import HorizontalLineChart

> from reportlab.lib import colors

> drawing = Drawing(250, 175)

the above makes little sense the height should be >= lc.y + lc.width and the
width >= lx.x + lc.height


> data = [ (3,3,3,10,14,1,1,1,11,13,12,7) ]

>

> lc = HorizontalLineChart()

> lc.x = 40

> lc.y = -175


for me the above makes no sense. It moves things below the bottom of the image.
I assume you are using this in some larger art board or a translated canvas
where this still allows the image to be seen.


> lc.height = 225

> lc.width = 610

> lc.data = data

> lc.joinedLines = 1

> lc.inFill = 0

>

> lc.categoryAxis.categoryNames = ['0:00','2:00','4:00',

> '6:00','8:00','10:00','12:00','14:00','16:00', '18:00','20:00','22:00']

> lc.valueAxis.valueMin = 0

> lc.valueAxis.valueMax = 15

> lc.lineLabelFormat = '%0.0f'

> lc.lineLabelNudge = 5

> lc.lines[0].strokeColor= colors.beige

>

> data3=[ (0,0,0,2,7,0,1,1,7,5,6,2),

> (0,0,0,5,5,0,0,0,0,0,0,1),

> (0,0,0,0,0,0,0,0,2,6,4,1),

> (1,1,1,1,1,0,0,0,1,1,1,1),

> (1,1,1,1,1,0,0,0,1,1,0,1),

> (0,1,1,0,0,0,0,0,0,0,0,1),

> (0,0,0,1,0,1,0,0,0,0,1,0)

> ]

> bc = VerticalBarChart()

> bc.x = lc.x

> bc.y = lc.y

> bc.height = lc.height

> bc.width = lc.width

> bc.data = data3

> bc.categoryAxis.style = 'stacked'

> bc.valueAxis.valueMin = 0

> bc.valueAxis.valueMax = lc.valueAxis.valueMax

> bc.categoryAxis.visibleAxis =0

> bc.categoryAxis.categoryNames = None

> drawing.add(bc)


I added
drawing.add(lc)




> drawing.save(formats=['pdf'],fnRoot='helga-000',outDir='/tmp')

> ##############################

>

> Before adding 'data3' the output look like in the first image below. The

> data point values with red arrows are on or below the line, when

> 'data3' is added


I am seeing only a white line on top of the bar chart, but only when I added the
line chart after the bar chart. Again



> (second image below) these marked values can no longer be seen. When I

> increase the 'lineLabelNudge', the values only move further from the line,

> or when I make it really small (e.g. 0.5), all the values move to on the

> line but are only half visible.

> Since in all the examples that I could find the values are shown above the

> lines, I wondered whether there is setting that I have missed ?

> Hope this was clearer,

> Regards,

> Helga



This code is showing both charts for me, but in an A4(nearly) sized drawing
##################################################################
if __name__=='__main__':
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.graphics.charts.linecharts import HorizontalLineChart
from reportlab.lib import colors
drawing = Drawing(595, 842)
data = [ (3,3,3,10,14,1,1,1,11,13,12,7) ]

lc = HorizontalLineChart()
lc.x = 40
lc.y = 100
lc.height = 225
lc.width = 610
lc.data = data
lc.joinedLines = 1
lc.inFill = 0

lc.categoryAxis.categoryNames = ['0:00','2:00','4:00',
'6:00','8:00','10:00','12:00','14:00','16:00', '18:00','20:00','22:00']
lc.valueAxis.valueMin = 0
lc.valueAxis.valueMax = 15
lc.lineLabelFormat = '%0.0f'
lc.lineLabelNudge = 5
lc.lines[0].strokeColor= colors.beige

data3=[ (0,0,0,2,7,0,1,1,7,5,6,2),
(0,0,0,5,5,0,0,0,0,0,0,1),
(0,0,0,0,0,0,0,0,2,6,4,1),
(1,1,1,1,1,0,0,0,1,1,1,1),
(1,1,1,1,1,0,0,0,1,1,0,1),
(0,1,1,0,0,0,0,0,0,0,0,1),
(0,0,0,1,0,1,0,0,0,0,1,0)
]
bc = VerticalBarChart()
bc.x = lc.x
bc.y = lc.y
bc.height = lc.height
bc.width = lc.width
bc.data = data3
bc.categoryAxis.style = 'stacked'
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = lc.valueAxis.valueMax
bc.categoryAxis.visibleAxis =0
bc.categoryAxis.categoryNames = None
drawing.add(bc)
drawing.add(lc)
drawing.save(formats=['pdf'],fnRoot='helga-001',outDir='/tmp/helga')
##################################################################

--
Robin Becker


More information about the reportlab-users mailing list