I’m trying to automate the creation of some bar graphs, and I’m able to do everything except display the height of each bar above it. Here is the code I have so far:
def add_bar_chart_slides():
prs = Presentation()
slide_layout = prs.slide_layouts[6] # Use the layout for title and content
slide = prs.slides.add_slide(slide_layout)
chart_data = CategoryChartData()
chart_data.categories = ['Category 1', 'Category 2', 'Category 3', 'Category 4']
chart_data.add_series('Series 1', (581, 581, 243, 121))
x, y, cx, cy = Inches(1), Inches(.5), Inches(8), Inches(6.5) # Position and size of the chart
chart = slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
).chart
for i, point in enumerate(chart.series[0].points):
fill = point.format.fill
fill.solid()
if i == 0:
fill.fore_color.rgb = RGBColor(0, 112, 192) # RGB value for blue
else:
fill.fore_color.rgb = RGBColor(191, 191, 191) # RGB value for gray
But I’m not able to figure out how to add the y labels above each bar like in the screenshot below. Can someone help me with this?