我正在使用openpyxl(此模块在xlsxwriter上使用,因为我需要访问并写入到先前存在的工作簿中)才能创建多个条形图。我删除了网格线和X / Y轴,并添加了数据标签。我无法弄清楚如何使数据标签不重叠(不使标签垂直)。我是Python的新手,所以非常感谢格式化提示!谢谢!
from openpyxl.chart import BarChart,Reference
from openpyxl.chart.label import DataLabelList
from openpyxl.chart.text import RichText
from openpyxl.drawing.text import CharacterProperties, ParagraphProperties, Paragraph
axis = CharacterProperties(sz=550)
rot = openpyxl.drawing.text.RichTextProperties(vert='eaVert')
sheet = book['Graph Info']
valuesQT = Reference(sheet, min_col = 8, min_row = 3, max_col = 10, max_row = 11)
catsQT = Reference(sheet, min_col = 7, min_row = 4, max_col = 7, max_row = 11)
chartQT = BarChart()
#Formatting Code Start
chartQT.y_axis.majorGridlines = None
chartQT.x_axis.majorGridlines = None
chartQT.dLbls = DataLabelList()
chartQT.dLbls.showVal = 1
chartQT.dLblsPos='bestFit'
#chartQT.separator = True
chartQT.dLbls.txPr = RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=axis), endParaRPr=axis)], bodyPr=rot)
chartQT.y_axis.delete = True
chartQT.type = "col"
chartQT.style = 10
chartQT.add_data(valuesQT, titles_from_data=True)
chartQT.set_categories(catsQT)
chartQT.shape = 4
chartQT.height = 6
chartQT.width = 12
chartQT.title = " Change "
sheet = book['Summary']
sheet.add_chart(chartQT, "A1")
writer.save()