1 Star 0 Fork 0

wangzhensuo/japanese_count

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
openpyxl_chart.py 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
wangqiang 提交于 2021-09-28 17:32 . dd
from openpyxl import load_workbook
from openpyxl.chart import PieChart, Reference
from openpyxl.chart.series import DataPoint
from openpyxl.chart.label import DataLabelList
# data = [
# ['Pie', 'Sold'],
# ['Apple', 50],
# ['Cherry', 30],
# ['Pumpkin', 10],
# ['Chocolate', 40],
# ]
workbook = load_workbook(filename = 'cpjg.xlsx')
ws = workbook.active
# for row in data:
# ws.append(row)
pie = PieChart()
labels = Reference(ws, min_col=1, min_row=2, max_row=5)
data = Reference(ws, min_col=2, min_row=1, max_row=5)
pie.add_data(data, titles_from_data=True)
pie.set_categories(labels)
pie.title = "各词性百分比"
pie.dataLabels = DataLabelList()
pie.dataLabels.showVal = True
pie.dataLabels.showCatName = True
pie.dataLabels.showSerName = True
pie.dataLabels.showPercent = True
slice = DataPoint(idx=0, explosion=20)
pie.series[0].data_points = [slice]
ws.add_chart(pie, "D1")
workbook.save('cpjg.xlsx')
# ----------------------------------------------------
# https://www.osgeo.cn/openpyxl/charts/radar.html
# 用雷达图对单词的范围进行评定
from openpyxl import Workbook
from openpyxl.chart import (
RadarChart,
Reference,
)
wb = Workbook()
ws = wb.active
rows = [
['词汇', "Bulbs"],
['四级', 23],
['六级', 53],
['考研', 223],
['雅思', 3],
['托福', 43]
]
for row in rows:
ws.append(row)
chart = RadarChart()
chart.type = "filled"
labels = Reference(ws, min_col=1, min_row=2, max_row=13)
data = Reference(ws, min_col=2, max_col=5, min_row=1, max_row=13)
chart.add_data(data, titles_from_data=True)
chart.set_categories(labels)
chart.style = 1
chart.title = "Garden Centre Sales"
chart.y_axis.delete = True
ws.add_chart(chart, "A17")
wb.save("radar.xlsx")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wangzhensuo/japanese_count.git
git@gitee.com:wangzhensuo/japanese_count.git
wangzhensuo
japanese_count
japanese_count
master

搜索帮助