Skip to content Skip to sidebar Skip to footer

Create Point In Graph Using Xslwriter

I am able to generate graph using xlsxwriter in Python by line properties. But I need to put 4 dots(diamond) on the particular value. Can anyone suggest me How Can I put diamond o

Solution 1:

In XlsxWriter it isn't possible to turn on individual point markers in a series but it is possible to turn point markers off for a series with markers. To do this you need to use the points (see docs) series option and turn off markers that you don't want.

from xlsxwriter.workbook import Workbook

workbook = Workbook('chart_point.xlsx')

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

data = [
    [1, 2, 3, 4, 5],
    [2, 4, 6, 8, 10],
    [3, 6, 9, 12, 15],

]

# Write the data for the chart.
worksheet.write_column('A1', data[0])
worksheet.write_column('B1', data[1])
worksheet.write_column('C1', data[2])

# Add a chart series with markers but turn some off.
chart.add_series({
    'categories': '=Sheet1!$A$1:$A$5',
    'values': '=Sheet1!$B$1:$B$5',
    'marker': {'type': 'automatic'},
    'points': [
            {'fill': {'none': True}, 'line': {'none': True}},
            {'fill': {'none': True}, 'line': {'none': True}},
            {'fill': {'none': True}, 'line': {'none': True}},
            {'fill': {'none': True}, 'line': {'none': True}},
    ],
})

# Add a second chart series.
chart.add_series({
    'categories': '=Sheet1!$A$1:$A$5',
    'values': '=Sheet1!$C$1:$C$5',
    'marker': {'type': 'automatic'},
    'points': [
            {'fill': {'none': True}, 'line': {'none': True}},
            {},
            {'fill': {'none': True}, 'line': {'none': True}},
            {'fill': {'none': True}, 'line': {'none': True}},
            {'fill': {'none': True}, 'line': {'none': True}},
    ],
})

worksheet.insert_chart('E9', chart)

workbook.close()

enter image description here

This implies that you can only indicate markers that are part of the series, i.e., there is no facility in XlsxWriter for adding a point to a chart that isn't part of a series.

Post a Comment for "Create Point In Graph Using Xslwriter"