Last active
July 27, 2016 23:16
-
-
Save boertel/4d3ab4ab7eb115eba30089fe0cc9ce53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xlsxwriter | |
workbook = xlsxwriter.Workbook('chart.xlsx') | |
worksheet = workbook.add_worksheet() | |
# Create a new Chart object. | |
chart = workbook.add_chart({'type': 'column'}) | |
# Write some data to add to plot on the chart. | |
data = [ | |
{'name': 'Los Angeles', 'value': 0.056}, | |
{'name': 'Chicago', 'value': 0.04}, | |
] | |
names = [] | |
values= [] | |
for d in data: | |
names.append(d['name']) | |
values.append(d['value']) | |
start = 1 | |
end = len(names) | |
worksheet.write_column('A1', names) | |
worksheet.write_column('B1', values) | |
chart.add_series({ | |
'categories': '=Sheet1!A%s:A%s' % (start, end), | |
'values': '=Sheet1!B%s:B%s' % (start, end), | |
}) | |
# Insert the chart into the worksheet. | |
worksheet.insert_chart('A7', chart) | |
workbook.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment