openpyxl 制作Chart X Y轴颠倒

Gordon_Chen 2020-05-10 08:11:30
请教论坛里面的大神,如何用openpyxl实现下面的Chart啊?
我的Excel里面的数据是横向排列的,不知道怎么在Reference里面引用数据了。


...全文
329 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gordon_Chen 2020-05-11
  • 打赏
  • 举报
回复
引用 5 楼 weixin_45903952 的回复:
你把数据转置一下,引用看看
我转置后是正确的。可是实际报表数据是横着的数据,郁闷啊
weixin_45903952 2020-05-11
  • 打赏
  • 举报
回复
引用 6 楼 Gordon_Chen 的回复:
[quote=引用 5 楼 weixin_45903952 的回复:] 你把数据转置一下,引用看看
我转置后是正确的。可是实际报表数据是横着的数据,郁闷啊[/quote] 这也是我郁闷的地方,没办法,只认纵向的数据
weixin_45903952 2020-05-10
  • 打赏
  • 举报
回复
你把数据转置一下,引用看看
weixin_45903952 2020-05-10
  • 打赏
  • 举报
回复
引用 3 楼 Gordon_Chen 的回复:
@weixin_45903952 我参照你的帖子,做出来是下面这样的。 from openpyxl import Workbook from openpyxl import load_workbook from openpyxl.chart import BarChart, Series, Reference wb = load_workbook('a55aa.xlsx') ws = wb.get_sheet_by_name("New Title") chart1 = BarChart() chart1.type = "col" chart1.style = 10 chart1.title = "Bar Chart" chart1.y_axis.title = 'Test number' chart1.x_axis.title = 'Sample length (mm)' data = Reference(ws, min_col=8,max_col=9, min_row=9) cats = Reference(ws, min_col=8,max_col=9, min_row=8,max_row=8) chart1.add_data(data,titles_from_data=True) chart1.set_categories(cats) chart1.shape = 4 ws.add_chart(chart1, "A20") wb.save('a55aa.xlsx') 比之前有进步,感觉快要成功了。
好像是引用的数据不对,数据就是一组,100,150
Gordon_Chen 2020-05-10
  • 打赏
  • 举报
回复
@weixin_45903952 我参照你的帖子,做出来是下面这样的。 from openpyxl import Workbook from openpyxl import load_workbook from openpyxl.chart import BarChart, Series, Reference wb = load_workbook('a55aa.xlsx') ws = wb.get_sheet_by_name("New Title") chart1 = BarChart() chart1.type = "col" chart1.style = 10 chart1.title = "Bar Chart" chart1.y_axis.title = 'Test number' chart1.x_axis.title = 'Sample length (mm)' data = Reference(ws, min_col=8,max_col=9, min_row=9) cats = Reference(ws, min_col=8,max_col=9, min_row=8,max_row=8) chart1.add_data(data,titles_from_data=True) chart1.set_categories(cats) chart1.shape = 4 ws.add_chart(chart1, "A20") wb.save('a55aa.xlsx') 比之前有进步,感觉快要成功了。
weixin_45903952 2020-05-10
  • 打赏
  • 举报
回复
参照官方或我这个 https://blog.csdn.net/weixin_45903952/article/details/105126839#comments_12157166
weixin_45903952 2020-05-10
  • 打赏
  • 举报
回复
这个问题我也遇到过,只能先把表格用.T转置,才能用refrence,要不数据就是引用错误,希望大佬们能有别的解决办法

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧