Skip to content

When changing data label colors, categories won't show #650

@emmartin-design

Description

@emmartin-design

Hello!

If I set category names to show, without changing anything else, categories show as expected.
chart.plots[0].data_labels.show_category_name = True

However, because I need some data labels to be white, and some to be dark due to the background they appear over, I need to set up code that goes point by point and changes the color. When this is done, the categories will not show. The following is the code I'm currently using to achieve this.

def differing_data_labels(chart, ic, nos, noc):
for series_color, series in enumerate(chart.series):

    for point_color, point in enumerate(series.points):
        pointcolor = point.data_label.font.color
        pointcolor.theme_color = MSO_THEME_COLOR.TEXT_1
        if ic == 'PIE':
            point.data_label.position = XL_LABEL_POSITION.BEST_FIT
            cbreak = colorbreak(noc)
            if point_color < cbreak:
                pointcolor.theme_color = MSO_THEME_COLOR.BACKGROUND_1
            point.data_label.show_category_name = True
        else:
            cbreak = colorbreak(nos)
            if series_color < cbreak:
                pointcolor.theme_color = MSO_THEME_COLOR.BACKGROUND_1

No matter where I place the command to show the categories, if the points have been iterated over, it seems to override the command and no categories will show. In addition, when running the command as part of the iteration seems to have no effect: point.data_label.show_category_name = True

Other such commands, such as show_data_labels, do not have this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions