I am creating charts using openpyxl with the following code. By default it doesn't show data labels - so I have to right-click the chart and choose 'Add Data Labels" manually. How do I do that with Openpyxl command? Thanks in advance !
data = Reference(ws, min_col=2, min_row=1, max_col=6, max_row=10)
titles = Reference(ws, min_col=1, min_row=2, max_row=10)
chart = BarChart3D()
chart.add_data(data=data, titles_from_data=True)
chart.set_categories(titles)
ws.add_chart(chart, "C10")
This works for me on a line chart (As a combination chart): openpyxls version: 2.3.2:
from openpyxl.chart.label import DataLabelList
chart2 = LineChart()
.... code to build chart like add_data()
and: # Style the lines
s1 = chart2.series[0]
s1.marker.symbol = "diamond"
... your data labels added here:
chart2.dataLabels = DataLabelList()
chart2.dataLabels.showVal = True
Hope this helps someone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With