[reportlab-users] Issues with pie chart labeling

Gautama Bharadwaj gautama at chipster.in
Thu Jul 16 06:34:39 EDT 2020


Hello!

I hope this email finds you well. I am currently using ReportLab 3.5.44 
and I have an issue with the pie-chart labeling. Pardon me if this is an 
issue that has been addressed before, however, I could not find any 
solution after going through the mailing list archives.

The pie chart I need to generate has data that generates labels closely 
spaced as shown in Figure 1 in the attachment. This is a watered down 
version of the code I'm working with :

fromreportlab.graphics.charts.piecharts importPie
fromreportlab.graphics.shapes importDrawing
fromreportlab.lib.units importmm
fromreportlab.pdfgen importcanvas
importreportlab.lib.colors ascolors
defpiechart(chart_colors):
d =Drawing(0*mm, 0*mm)
dn =Pie()
dn.startAngle =45
dn.x =0*mm
dn.y =0*mm
dn.width =60*mm
dn.height =60*mm
dn.data =[1141182.0, 105950.0, 68107.0,
49615.0, 26925.0, 3678.0, 842.0, 421.0]
dn.innerRadiusFraction =0.7
dn.slices.fontSize =10
dn.labels =["(The first label)", "(The second label)",
"(The third label)", "(The fourth label)",
"(The fifth label)", "(The sixth label)",
"(The seventh label)", "(The eighth label)"]
dn.sideLabels =1
dn.checkLabelOverlap =1
dn.slices.label_simple_pointer =0
dn.simpleLabels =0
# dn.slices.label_maxWidth = 20*mm
dn.slices.label_pointer_strokeColor =colors.HexColor("#aeaeae")
dn.slices.labelRadius =1.2
dn.slices.strokeColor =None
fori inrange(0, len(dn.data)):
dn.slices[i].fillColor =colors.HexColor(chart_colors[i])
d.add(dn)
returnd
if__name__ =="__main__":
c =canvas.Canvas("piechart.pdf")
downtime_colors =[
"#b34700",
"#cc5100",
"#e65b00",
"#ff6500",
"#ff741a",
"#ff8433",
"#ff934d",
"#ffa267",
"#ffb280",
"#ffc19a",
]
chart =piechart(downtime_colors)
chart.drawOn(c, 80*mm, 150*mm)
c.showPage()
c.save()

I have set "sideLabels" and "checkLabelOverlap" as "1" but there is 
still a bit of an overlap (Figure 1).

*Question 1: Is there any way, I can add more spacing between 2 labels? *

I also wish to add a "label_maxWidth" (see comment in the code) to the 
labels and have thus set "simpleLabels" to 0. However, when I do this 
the labels overlap more than it had without this. (Figure 2)

*Question 2: Can I also set "label.maxWidth" by maintaining the spacing 
between 2 labels*

Please do let me know if I'm missing something or if I'm doing something 
wrong. Thank you in advance and I truly appreciate your time!


-- Warm regards, Gautama Bharadwaj

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20200716/ab0ffab9/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Figure 1.png
Type: image/png
Size: 13248 bytes
Desc: not available
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20200716/ab0ffab9/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Figure 2.png
Type: image/png
Size: 13078 bytes
Desc: not available
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20200716/ab0ffab9/attachment-0003.png>


More information about the reportlab-users mailing list