Skip to content Skip to sidebar Skip to footer

How To Remove A Legend Name In Openpyxl

--------------- CODE SNIPPET--------------- So the code goes like this. There's some code to create a bar chart. # create barChart barChart= BarChart() barChartData= Reference(wor

Solution 1:

I'm using openpyxl 3.0.9.

Looked into the source code for an idea and got this to work:

import openpyxl
chart.x_axis = openpyxl.chart.axis.TextAxis(delete=True)

Here is more of the code:

CHART_ROW = 11CHART_HEIGHT = 12DATA_TABLE_START_ROW = 34LENGTH_DIST_START_COL = 1SPACER_DIST_START_COL = LENGTH_DIST_START_COL + 10SPACER_RANGE_START_COL = SPACER_DIST_START_COL + 6

. . . .

    chart = BarChart()
    chart.style = style  # 1 = black line, 13 = green bold line
    chart.title = "Spacer Distribution Summary"
    chart.height = CHART_HEIGHT  # default is 7.5
    chart.width = 7# default is 15
    chart.y_axis.title = 'Target Spacer Frequency'
    chart.x_axis = openpyxl.chart.axis.TextAxis(delete=True)

    values = Reference(self.sheet,
                       min_col=SPACER_DIST_START_COL + 1,
                       max_col=SPACER_DIST_START_COL + 1,
                       min_row=self.spacer_distribution_first_row,
                       max_row=self.spacer_distribution_last_row)
    series = Series(values, title_from_data=False)
    chart.series.append(series)
    # chart.legend = None
    pos = f"{column_string(SPACER_DIST_START_COL)}{CHART_ROW}"
    self.sheet.add_chart(chart, pos)

Solution 2:

Following your error code to the openpyxl documentation, we find the usage:

openpyxl.chart.legend.Legend(legendEntry=())

So you enter in the legendEntry the list you want to update the figure to. I believe in your case this will be

chartABC.legend.Legend(legendEntry=(['test', 'test', 'test']))

Post a Comment for "How To Remove A Legend Name In Openpyxl"