def use_bar():
from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches
ppt = Presentation()
slide = ppt.slides.add_slide(ppt.slide_layouts[6])
# 封装图表数据
char_data = CategoryChartData()
# 分组数据
char_data.categories = ['第一季度', '第二季度', '第三季度', '第四季度']
# 具体数据
char_data.add_series('series', (19, 21, 16))
x = y = Inches(2)
width = Inches(6)
height = Inches(4.5)
# 绘制图表
# slide.shapes.add_chart(XL_CHART_TYPE.COlUMN_CLUSTERED, x, y, width, height, char_data)
slide.shapes.add_chart(XL_CHART_TYPE.COlUMN_CLUSTERED)
ppt.save('./created data/29_绘制图纸条图.pptx')
if __name__ == '__main__':
use_bar()
C:\Programs\Winpython64-3.8.3\WPy64-3830\python-3.8.3.amd64\python.exe "C:\Users\101859\OneDrive - Grundfos\Work\Self Doc\Python\Exercise\29_图表绘制.py"
Traceback (most recent call last):
File "C:\Users\101859\OneDrive - Grundfos\Work\Self Doc\Python\Exercise\29_图表绘制.py", line 25, in <module>
use_bar()
File "C:\Users\101859\OneDrive - Grundfos\Work\Self Doc\Python\Exercise\29_图表绘制.py", line 20, in use_bar
slide.shapes.add_chart(XL_CHART_TYPE.COlUMN_CLUSTERED)
AttributeError: type object 'XL_CHART_TYPE' has no attribute 'COlUMN_CLUSTERED'
Process finished with exit code 1