CWC
CWC

Reputation: 33

XlsxWriter - setting gridlines color

I'm wondering if one can set the color for major or minor gridlines when adding charts.

The documentation shows an example of setting 'visible' : True/False and 'dash_style', but when I pass a parameter for 'color' there is no change.

I assume the gridline instance of 'line' does not have a 'color' parameter, but am asking in case I'm missing the solution.

chart.set_x_axis({
    'major_gridlines': {
        'visible': True,
        'line': {'width': 1.25, 'dash_type': 'dash', 'color' : 'red'}
    },
})

Upvotes: 2

Views: 3573

Answers (1)

jmcnamara
jmcnamara

Reputation: 41644

The code you posted should work as expected.

Here is the code in a working example:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()
chart = workbook.add_chart({'type': 'line'})


worksheet.write_column('A1', [5, 4, 9, 12, 7])

chart.add_series({'values': '=Sheet1!$A$1:$A$5'})

chart.set_x_axis({
    'major_gridlines': {
        'visible': True,
        'line': {'width': 1.25, 'dash_type': 'dash', 'color' : 'red'}
    },
})

worksheet.insert_chart('A7', chart)

workbook.close()

And here is the output:

enter image description here

Upvotes: 3

Related Questions