ChartLegend class

ChartLegend class

Represents chart legend properties. To learn more, visit the Working with Charts documentation article.

Properties

NameDescription
fontProvides access to the default font formatting of legend entries. To override the font formatting for a specific legend entry, use theChartLegendEntry.font property.
formatProvides access to fill and line formatting of the legend.
legend_entriesReturns a collection of legend entries for all series and trendlines of the parent chart.
overlayDetermines whether other chart elements shall be allowed to overlap legend. Default value is False.
positionSpecifies the position of the legend on a chart. Default value is LegendPosition.RIGHT.

Examples

Shows how to edit the appearance of a chart’s legend.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

shape = builder.insert_chart(aw.drawing.charts.ChartType.LINE, 450, 300)
chart = shape.chart

self.assertEqual(3, chart.series.count)
self.assertEqual("Series 1", chart.series[0].name)
self.assertEqual("Series 2", chart.series[1].name)
self.assertEqual("Series 3", chart.series[2].name)

# Move the chart's legend to the top right corner.
legend = chart.legend
legend.position = aw.drawing.charts.LegendPosition.TOP_RIGHT

# Give other chart elements, such as the graph, more room by allowing them to overlap the legend.
legend.overlay = True

doc.save(ARTIFACTS_DIR + "Charts.chart_legend.docx")

See Also