"Vertical bar with line labels" import reportlab from reportlab.graphics.charts.barcharts import VerticalBarChart from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin from reportlab.lib.colors import blue, PCMYKColor from reportlab.graphics.charts.textlabels import LabelOffset class VBarChartWLineBarLabels01(_DrawingEditorMixin,Drawing): """ Chart Features -------------- This is a simple vertical barchart with bar labels connected to the top and bottom of the chart depending on the sign of the data: - The bars have labels which are connected to the bars by lines. If the bar is positive the label is at the top else it will be at the chart bottom. - The attributes which control the label position in this case are **chart.barLabels.fixedEnd = LabelOffset()** - the labels will end at a dynamically controlled offset. - **self.chart.barLabels.fixedEnd.posMode='high'** - positive bars will be at the top of the chart: **self.chart.barLabels.fixedEnd.pos = 10** - negative bars will have labels at the bottom: **chart.barLabels.fixedEnd.negMode='low'** - with this y offset: **chart.barLabels.fixedEnd.neg = -10** - the normal (positive case) labels will be anchored south: **chart.barLabels.boxAnchor='s'** - Negative cases 'do the 'right thing' for boxAnchor and dy: **self.chart.barLabels.dy = -1** This chart was built with our [Diagra](http://www.reportlab.com/software/diagra/) solution. Not the kind of chart you looking for? Go [up](..) for more charts, or to see different types of charts click on [ReportLab Charts Gallery](/chartgallery/). """ def __init__(self,width=400,height=200,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self._add(self,VerticalBarChart(),name='chart',validate=None,desc=None) self.chart.barLabelFormat = '%s' self.chart.barLabels.lineStrokeColor = blue self.chart.barLabels.lineStrokeWidth = 1 self.chart.y = 20 self.chart.width=self.width-self.chart.x - 5 self.chart.height=self.height-2*self.chart.y self.chart.data = [(100, -110),(25,-30)] self.chart.barLabels.fixedEnd = LabelOffset() self.chart.barLabels.fixedEnd.posMode='high' self.chart.barLabels.fixedEnd.negMode='low' self.chart.barLabels.fixedEnd.pos = 10 self.chart.barLabels.fixedEnd.neg = -10 self.chart.barLabels.boxAnchor='s' self.chart.barLabels.dy = -1 self.chart.bars[0].fillColor = PCMYKColor(100,60,0,50,alpha=85) self.chart.bars[1].fillColor = PCMYKColor(100,0,90,50,alpha=85) if __name__=="__main__": #NORUNTESTS VBarChartWLineBarLabels01().save(formats=['pdf'],outDir='.',fnRoot=None)