Изменить Trendline-Color с openPyxl - PullRequest
0 голосов
/ 28 января 2020

Я пытаюсь написать скрипт на Python с openpyxl, который сохраняет данные в Excel-файле, а также aws диаграмму рассеяния с некоторыми линиями тренда. Проблема с openpyxl в том, что линии тренда в режиме по умолчанию всегда окрашены в черный цвет, и поэтому мой вопрос в том, как их покрасить в разные цвета.

from openpyxl.chart import * 
from openpyxl.chart.trendline import Trendline 
from openpyxl.styles import *
from openpyxl.chart.shapes import *
from openpyxl.drawing.colors import *

wb = Workbook()
ws = wb.create_sheet(name)

    #writes the Headlines of the columns into excel-file
for c in range(1,5):
    ws.cell(1, c).value = ueberschriften[c-1]

    #writes the data into excel-file
for c in range(2, points+2): 
    e = c-2
    for d in range(1,5):
        f = d-1
        b = a[e][f]
        ws.cell(c, d).value = b

for row in a:
    ws.append(row)        

chart = ScatterChart()
chart.title = "Measuring"
chart.style = 13
chart.x_axis.title = 'Time'
chart.y_axis.title = 'Value'

xvalues = Reference(ws, min_col=1, min_row=2, max_row=points+1)
for i in range(2, 5):
    values = Reference(ws, min_col=i, min_row=1, max_row=points+1)
    series = Series(values, xvalues, title_from_data=True)
    chart.series.append(series)

l = chart.series[0]
l.graphicalProperties.line.solidFill = "FF0000"
l.trindline = Trendline(trendlineType = 'poly', order = fit_order) #trendline with polinomial fitting

l1 = chart.series[1]
l1.graphicalProperties.line.solidFill = "0000FF"
line1.trendline = Trendline(trendlineType = 'poly', order = fit_order)

l2 = chart.series[2]
l2.graphicalProperties.line.solidFill = "00FF00"
l2.trendline = Trendline(trendlineType = 'poly', order = fit_order)

ws.add_chart(chart, "A10")

wb.save("C:\****\****\testFile.xlsx")```

...