"A Vertical Bar Chart With Line Indicated Bar Labels" #Autogenerated by ReportLab guiedit do not edit import reportlab from reportlab.graphics.charts.barcharts import VerticalBarChart from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin from reportlab.lib.colors import blue from reportlab.graphics.charts.textlabels import LabelOffset class VBarChartWLineBarLabels02(_DrawingEditorMixin,Drawing): """ 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. Unlike the 01 version this chart connects the axis end of the bar to the label. Chart Features -------------- This chart demonstrates different unique features such as - 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 - self.chart.barLabels.fixedEnd = LabelOffset() the labels will end at a dynamically controlled offset. - self.chart.barLabels.fixedEnd.posMode='low' positive bars will be at the bottom of the chart - self.chart.barLabels.fixedEnd.pos = -10 with this offset. - self.chart.barLabels.fixedEnd.negMode='high' negative bars will have labels at the top - self.chart.barLabels.fixedEnd.neg = 10 with this y offset - self.chart.barLabels.boxAnchor='n' the normal (positive case) labels will be anchored st their north side. - self.chart.barLabels.dy = -1 with this small adjustment. Negative cases 'do the 'right thing' for boxAnchor and dy. - self.chart.barLabels.fixedStart = LabelOffset() this object fixes the start of the lines - self.chart.barLabels.fixedStart.posMode='axis' at the axis for both positive - self.chart.barLabels.fixedStart.negMode='axis' and negative bars. This chart was built with our [Diagra][dialink] solution. Not the kind of chart you looking for? Do not worry go [up][up_link] for more charts, or to see different types of charts click on [ReportLab Charts Gallery][gallink]. [uplink]: .. [gallink]: /chartgallery/ "ReportLab Charts Gallery" [dialink]: http://www.reportlab.com/software/diagra/ """ 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='low' self.chart.barLabels.fixedEnd.pos = -10 self.chart.barLabels.fixedEnd.negMode='high' self.chart.barLabels.fixedEnd.neg = 10 self.chart.barLabels.boxAnchor='n' self.chart.barLabels.dy = 1 self.chart.barLabels.fixedStart = LabelOffset() self.chart.barLabels.fixedStart.posMode='axis' self.chart.barLabels.fixedStart.negMode='axis' if __name__=="__main__": #NORUNTESTS VBarChartWLineBarLabels02().save(formats=['pdf'],outDir='.',fnRoot=None)