def dates(wb): ws = wb.create_sheet(3, "Dates") for i in range(1, 10): ws.append([date(2013, i, 1), i]) chart = BarChart() values = Reference(ws, (0, 1), (8, 1)) labels = Reference(ws, (0, 0), (8, 0)) labels.number_format = 'd-mmm' series = Series(values, labels=labels) chart.append(series) ws.add_chart(chart)
def test_label_number_format(self): ws = self.make_worksheet() for i in range(10): ws.append([i, i]) labels = Reference(ws, (0,0), (0,9)) labels.number_format = 'd-mmm' values = Reference(ws, (0,0), (0,9)) serie = Serie(values=values, labels=labels) c = BarChart() c.add_serie(serie) cw = BarChartWriter(c) root = Element('test') cw._write_serial(root, c._series[0].labels) expected = """<?xml version='1.0' ?><test xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:numRef><c:f>'data'!$A$1:$J$1</c:f><c:numCache><c:formatCode>d-mmm</c:formatCode><c:ptCount val="10" /><c:pt idx="0"><c:v>0</c:v></c:pt><c:pt idx="1"><c:v>1</c:v></c:pt><c:pt idx="2"><c:v>2</c:v></c:pt><c:pt idx="3"><c:v>3</c:v></c:pt><c:pt idx="4"><c:v>4</c:v></c:pt><c:pt idx="5"><c:v>5</c:v></c:pt><c:pt idx="6"><c:v>6</c:v></c:pt><c:pt idx="7"><c:v>7</c:v></c:pt><c:pt idx="8"><c:v>8</c:v></c:pt><c:pt idx="9"><c:v>9</c:v></c:pt></c:numCache></c:numRef></test>""" xml = get_xml(root) diff = compare_xml(xml, expected) assert diff is None, diff
values = Reference(ws, (0, 1), (9, 1)) series = Serie(values, labels=labels) chart.add_serie(series) # add second series values = Reference(ws, (0, 2), (9, 2)) series = Serie(values, labels=labels) chart.add_serie(series) ws.add_chart(chart) ws = wb.create_sheet(3, "Dates") for i in range(1, 10): ws.append([date(2013, i, 1), i]) chart = BarChart() values = Reference(ws, (0, 1), (9, 1)) labels = Reference(ws, (0, 0), (9, 0)) labels.number_format = 'd-mmm' series = Serie(values, labels=labels) chart.add_serie(series) ws.add_chart(chart) ws = wb.create_sheet(4, "Pie") for i in range(1, 5): ws.append([i]) chart = PieChart() values = Reference(ws, (0, 0), (9, 0)) series = Serie(values, labels=values) chart.add_serie(series) ws.add_chart(chart) ws = wb.create_sheet(5, "Line") for i in range(1, 5):