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 doesn'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.>br>
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:
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 chart
chart = LineChart()
chart.style = 12
chart.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 = E2
sheet.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"
Rather than using
titles_from_data=True, create series for your data and set the title as you requireNeed to import 'Series' from 'openpyxl.chart' as well.
Working Example;
The following example is a self contained example that incorporates your code as able and uses dummy data.
Ensure that you are using the latest Openpyxl release, 3.1.2