Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Changing the name of an excel chart series with openpyxl, with python

$
0
0

So, I'm making some line charts with openpyxl and to make them I changed the key strings of the dict (that is going as input for the workbook) to not be equal and always be a different string, so the data don't overwrite because some key string was equal. The problem is, in the chart series name, I need them to be unchanged and not the title from the data column but the unchanged string that i have stored on other list.Is it possible to just change the name of the series in the chart and leave the column name not changed? (if the column name changed for the name i want the series name to be it was going to exist more than one column with the same name.)

This is the code I have for this:

x_values = Reference(sheet, min_col=1, min_row=2, max_col=1, max_row=sheet.max_row)y_values = Reference(sheet, min_col=column_init, min_row=row_num, max_col=column_end, max_row=sheet.max_row)Create the chartchart = LineChart()chart.add_data(data)chart.style = 12chart.add_data(y_values, titles_from_data=True)chart.set_categories(y_values)chart.set_categories(x_values)chart.x_axis.number_format = 'hh:mm'  # 'dd-mm-yyyy hh:mm:ss'chart.x_axis.majorTimeUnit = "hours"chart.x_axis.title = "Date"graph_location = E2sheet.add_chart(chart, graph_location)book.save(excel_name)

I tried to change the series title, but that's not right and throws errors about the object type.

chart.series.title = "SeriesName-bup"

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>