Is it possible to change the color associated with the legend of a chart created in Openpyxl?
I have created a relatively simple chart using my data but would like to force the colors it uses to create each piece. Here's the snippet of my code related to the chart:
chart = PieChart()
data = Reference(worksheet, min_col=2, min_row=4, max_row=7, max_col=2)
categories = Reference(worksheet, min_col=1, min_row=4, max_row=7, max_col=1)
chart.add_data(data)
chart.set_categories(categories)
worksheet.add_chart(chart, 'D3')
The easiest way to change the color is to change the color scheme via styles:
There are two other ways that I have not looked into but you may be able to modify the colors using more obscure methods.
The first is through the a member in this class:
The
spPr
member which is expecting GraphicalProperties to be assigned and you may be able to modify this to change the color.The second possibility is to create your own style and assign it using the previously mentioned command.
If you want to change the colors of each series in the legend, you should change the color of the lines for each series in your plot using something like this: