Wednesday, 24 March 2021

Creating complex Area Chart using openpyxl (transparency)

I am trying to create an area chart using openpyxl. I wish for the area chart to look more complex than the basic excel charts. Here is my data

data

month   group1  group2
jan     15      13
feb     19      15
mar     20      17
apr     25      24
may     29      30
jun     24      30
jul     16      40
aug     20      24
sep     22      20
oct     27      17
nov     17      26
dec     21      29

enter image description here

Desired

enter image description here

Doing

from openpyxl import load_workbook
from openpyxl.chart import BarChart, Reference, Series, ScatterChart, LineChart, StockChart, AreaChart, AreaChart3D



path = "C:/Users/thud/wb1.xlsx"
wb_obj = load_workbook(path)
sheet_obj = wb_obj.active



c1 = AreaChart()
c1.title = "Area Chart"
c1.y_axis.title = "Cost"
c1.x_axis.title = "Date"
c1.x_axis.number_format = 'mm/dd/yy'
c1.x_axis.majorTimeUnit = "days"
c1 = deepcopy(c1)
c1.style = 39


data = Reference(sheet_obj, min_col=2, min_row=2, max_col=3, max_row=13)
c1.add_data(data, titles_from_data=True)

dates = Reference(sheet_obj, min_col=1, min_row=2, max_row=13)
c1.set_categories(dates)


sheet_obj.add_chart(c1, "I2")
wb_obj.save("sample.xlsx")

I have found this in the documentation, but unsure of how to implement:

     openpyxl.drawing.effect.AlphaBiLevelEffect

I'd like to add transparency to the area chart and have it reflect my desired output. Any suggestion is appreciated



from Creating complex Area Chart using openpyxl (transparency)

No comments:

Post a Comment