Reputation: 61
I have the following code to create a line chart in Excel using openpyxl. The problem is that when the excel file is generated, the chart container is added to the worksheet, but it is empty and no chart is displayed. I've checked the reference object and looks fine. Any idea of what could be causing this?
c1 = LineChart()
c1.title = "Line Chart"
c1.style = 10
c1.y_axis.title = 'Utilization'
c1.x_axis.title = 'Month'
data = Reference(worksheet, min_col = 2, min_row = 2, max_col = 2, max_row = 10)
print(data) #this prints Sheet 1!$B$2:$B$10
c1.add_data(data)
worksheet.add_chart(c1, "E2")
Upvotes: 1
Views: 1275
Reputation: 11
ws = wb.create_sheet(title = work_sheet_name.replace('-', '_'))
Upvotes: 1
Reputation: 417
I had very similar issue with openpyxl. It turned out to be a hyphen character ('-') in the worksheet name which used later in the x and y data reference for series. I replaced the hyphen with underscore ('_') character and it worked. In your case replace the space in the worksheet name, or add single quotes before and after sheet name, i.e. 'Sheet 1'
Upvotes: 2