I am trying to set the line of an openpyxl scatter chart to green:
JavaScript
x
10
10
1
from openpyxl import *
2
3
book = workbook.Workbook()
4
ws = book.active
5
xRef = chart.Reference(ws, min_col=1, min_row=2, max_row=22)
6
yRef = chart.Reference(ws, min_col=2, min_row=2, max_row=22)
7
chart.Series(yRef, xvalues=xRef, title='test')
8
lineProp = drawing.line.LineProperties(solidFill = 'green')
9
series.graphicalProperties.line = lineProp
10
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:
JavaScript
1
3
1
lineProp = drawing.line.LineProperties(prstDash='dash')
2
series.graphicalProperties.line = lineProp
3
Advertisement
Answer
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
:
JavaScript
1
2
1
lineProp = drawing.line.LineProperties(solidFill = drawing.colors.ColorChoice(prstClr='green'))
2