如何设置openpyxl ScatterChart的线条颜色 [英] How to set line color of openpyxl ScatterChart

查看:224
本文介绍了如何设置openpyxl ScatterChart的线条颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将openpyxl散点图的线设置为绿色:

I am trying to set the line of an openpyxl scatter chart to green:

from openpyxl import *

book = workbook.Workbook()
ws = book.active
xRef = chart.Reference(ws, min_col=1, min_row=2, max_row=22)
yRef = chart.Reference(ws, min_col=2, min_row=2, max_row=22)
chart.Series(yRef, xvalues=xRef, title='test')
lineProp = drawing.line.LineProperties(solidFill = 'green')
series.graphicalProperties.line = lineProp    

虽然此代码不会引起任何问题,但它不会更改默认行的颜色.更改线条颜色的正确方法是什么?

While this code does not cause any problems, it does not change the line color from the default. What is the correct way to change the line color?

有趣的是,我可以使用以下方式将样式设置为虚线或点划线:

Interestingly I have no problem setting the style to dashed or dotted using:

lineProp = drawing.line.LineProperties(prstDash='dash')
series.graphicalProperties.line = lineProp

推荐答案

事实证明,线宽可以保持默认值.通过将solidFill设置为openpyxl.drawing.colors.ColorChoice的实例,我可以进行颜色更改:

As it turns out, the line width can remain default. I got the color change to work by setting solidFill to an instance of openpyxl.drawing.colors.ColorChoice:

lineProp = drawing.line.LineProperties(solidFill = drawing.colors.ColorChoice(prstClr='green'))

这篇关于如何设置openpyxl ScatterChart的线条颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆