[Python] show custom data label from cell range on chart openpyxl

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have a bar chart using some placeholder data for formatting purposes and I need to set the data labels to a range in my sheet. Basically the Label contains Value from Cells option in Label Options in excel.

    I've tried setting text properties on dLbl of each series but to no avail. I saw a comment that said it's possible with XML but there was no further information.

    Here's my code:

    label_list = Reference(ws, min_col=1, max_col=4, min_row=1, max_row=3) # a 3x4 range of numbers
    chart = BarChart()
    chart.type = 'col'
    chart.grouping = 'percentStacked'
    chart.overlap = 100
    chart.add_data(data=data) # this is a 3x4 range of value = 1
    chart.set_categories(labels=categories)

    for series in chart.series:
    series.dLbls = DataLabelList()
    series.dLbls.showVal = True
    series.dLbls.numFmt = '0.0'
    # something to customise the data label here?


    pls help

    Continue reading...

Compartilhe esta Página