def add_chart(self, sheetname, x_col, y_col): ws = self.wb[sheetname] xtitle = ws.cell(1, x_col).value ytitle = ws.cell(1, y_col).value chart = LineChart() chart.title = "%s - %s" % (ytitle, xtitle) chart.style = 13 chart.x_axis.title = xtitle chart.y_axis.title = ytitle chart.marker = True chart.smooth = True y_data = Reference(ws, min_col=y_col, min_row=1, max_col=y_col, max_row=self.current_row) chart.add_data(y_data, titles_from_data=True) x_data = Reference(ws, min_col=x_col, min_row=2, max_col=x_col, max_row=self.current_row) chart.set_categories(x_data) s0 = chart.series[0] s0.marker.symbol = "circle" s0.smooth = True if 0 == self.chart_row: self.chart_row = self.current_row ws.add_chart(chart, "A%d" % self.chart_row) # row height is 7.5/16 cm by default self.chart_row = self.chart_row + chart.height / 7.5 * 16 + 2