__author__ = '未昔/AngelFate'
__date__ = '2020/4/28 12:49'
import xlsxwriter
workbook = xlsxwriter.Workbook("chart_column.xlsx")
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
headings = ['Number', 'testA', 'testB']
data = [
['2020-4-21', '2020-4-22', '2020-4-23', '2020-4-24', '2020-4-25', '2020-4-26'],
[50, 40, 50, 60, 70, 50],
[30, 60, 60, 50, 40, 30],
]
worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
worksheet.write_column('C2', data[2])
chart_col = workbook.add_chart({'type': 'column'})
chart_col.add_series({
'name': '=Sheet1!$B$1',
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$B$2:$B$7',
'line': {'color': 'red'},
})
chart_col.add_series({
'name': '=Sheet1!$C$1',
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$C$2:$C$7',
'line': {'color': 'yellow'},
})
chart_col.set_title({'name': 'The xxx site Bug Analysis'})
chart_col.set_x_axis({'name': 'Test number'})
chart_col.set_y_axis({'name': 'Sample length (mm)'})
chart_col.set_style(1)
worksheet.insert_chart('A10', chart_col, {'x_offset': 25, 'y_offset': 10})
workbook.close()
