Pie Chart - 0% Values overlapping

Issue #806 resolved
created an issue

I'm creating a pie chart and the values are all overlapping when more than 2 are 0%.

Is there a way to ensure the percentage labels do not overlap for the pie chart?

def createPieChart(ws, countRows):
    pie = PieChart()

    pie.dataLabels = DataLabelList()
    pie.dataLabels.showPercent = True
    #pie.dataLabels.  -- fix overlapping 0s
    #update start index
    labels = Reference(ws, min_col=4, max_col=7, min_row=17)
    data = Reference(ws, min_col=4, max_col=7, min_row=20+countRows)
    pie.add_data(data, from_rows=True, titles_from_data=False)
    pie.title = "Execution Breakdown"
    pie.height = 7
    pie.width = 10
    ws.add_chart(pie, "I2")

Comments (6)

  1. CharlieC

    Can you provide a complete file? I suspect that Excel has some internal logic for layouting items here but it might be possible to learn from it.

  2. CharlieC

    The overlapping seems to be entirely dependent upon the application used to view the file. In Excel 2011 and 2016 for Mac there is no overlapping.

    When I use Excel to recreate the chart it defaults to not displaying the percentage, which certainly makes sense in this case.

    If you add some values to the chart you can experiment with various formatting options but dLblPos = 'BestFit is the default option. Alternatively, you can disable the labels for the series with 0% to prevent them overlapping.

  3. Log in to comment