"Doughnut Pie chart with basic legend" #Autogenerated by ReportLab guiedit do not edit from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin from reportlab.graphics.charts.piecharts import Pie from reportlab.lib.colors import darkblue, midnightblue, lightblue, skyblue, blue, lightskyblue, white from reportlab.graphics.charts.legends import Legend class PieChart08(_DrawingEditorMixin,Drawing): ''' Chart Features -------------- A pie chart that is transformed into a doughnut chart Create an inner radius (in effect creating the doughnut) - self.pie.innerRadiusFraction = 0.5 ''' def __init__(self,width=400,height=200,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self._add(self,Pie(),name='pie',validate=None,desc=None) self.pie.innerRadiusFraction = 0.5 self.pie.data = [1, 2.3, 1.7, 4.2,1.9] self._colours = midnightblue, darkblue, blue, lightblue, skyblue self.width = 500 self.height = 200 self.pie.height = 200 self.pie.width = 200 self.pie.x = 70 self.pie.strokeWidth = 1 self.pie.slices.strokeColor = white self.pie.slices.strokeWidth = 2 self._seriesNames = 'Widgets', 'Xenopods', 'Thingamajigs', 'Advanced Widgets', 'Unobtainiums', 'Farouts' self._add(self,Legend(),name='legend',validate=None,desc=None) self.legend.y = self.height/2 self.legend.columnMaximum = 6 self.legend.y = self.height-20 self.legend.x = 300 self.legend.fontName = 'Helvetica' self.legend.fontSize = 14 for i,v in enumerate(self.pie.data): self.pie.slices[i].fillColor = self._colours[i] self.legend.colorNamePairs = list(zip(self._colours, self._seriesNames)) if __name__=="__main__": #NORUNTESTS PieChart08().save(formats=['pdf'],outDir='.',fnRoot=None)