My code is as follows:
import pandas as pd
pd.options.mode.chained_assignment = None
import pptx
from pptx.util import Cm
from pptx.dml.color import RGBColor
from pptx.enum.chart import XL_CHART_TYPE
from pptx.chart.data import ChartData
## Select path from which the deck will be imported
path_import = r"XXXX.pptx"
## Select layout, layout number can be worked out from the options when you add a new slide
SLD_LAYOUT_TITLE_AND_CONTENT = 6 #Empty template
## Create instance of Presentation
prs = pptx.Presentation(path_import)
## Add slide with the pre-chosen format
slide_layout = prs.slide_layouts[SLD_LAYOUT_TITLE_AND_CONTENT]
slide = prs.slides.add_slide(slide_layout)
## Generate data
chart_data1 = ChartData()
chart_data1.categories = [f"TM {i}" for i in range(1,21)]
chart_data1.add_series('Series 1', [x for x in range(20)])
## Add chart
graphic_frame1 = slide.shapes.add_chart(chart_type=XL_CHART_TYPE.COLUMN_CLUSTERED,
x=Cm(0.75),
y=Cm(4.71),
cx=Cm(32.12),
cy=Cm(10.76),
chart_data=chart_data1)
## Add data labels to the chart
graphic_frame1.chart.plots[0].has_data_labels = True
## (Attempt to) add a turquoise fill to the data labels
graphic_frame1.chart.plots[0].data_labels.font.fill.solid()
graphic_frame1.chart.plots[0].data_labels.font.fill.fore_color.rgb = RGBColor(36,210,254)
## Change font colour to orange
graphic_frame1.chart.plots[0].data_labels.font.color.rgb = RGBColor(249,165,41)
## Save deck to path
path_export = r"YYYY.pptx"
prs.save(path_export)
This produces a slide with a chart that has orange font (as expected) but no turquoise fill. By fill I mean the background fill of the labels.
I've discovered that if I comment out the graphic_frame1.chart.plots[0].data_labels.font.color.rgb = RGBColor(249,165,41) line, the font colour becomes turquoise, which I don't think is the intended outcome.
My code is as follows:
This produces a slide with a chart that has orange font (as expected) but no turquoise fill. By fill I mean the background fill of the labels.
I've discovered that if I comment out the
graphic_frame1.chart.plots[0].data_labels.font.color.rgb = RGBColor(249,165,41)line, the font colour becomes turquoise, which I don't think is the intended outcome.