Introduction

Aspose.Cells FOSS supports creating charts directly inside Excel .xlsx files from Python. The library provides dedicated add_*() methods for 16 chart types (Line, Bar, Pie, Area, Scatter, Waterfall, Combo, Stock, Surface, Radar, Treemap, Sunburst, Histogram, Funnel, Box & Whisker, and Map). Of these, Line, Bar, Pie, Area, and Stock have full XML serialization support and save correctly to .xlsx. The remaining types can be created in memory but raise NotImplementedError when workbook.save() is called.

Charts are added via worksheet.charts.add_*() methods that accept a bounding box defined by (upper_left_row, upper_left_column, lower_right_row, lower_right_column) as zero-based indices. Series data is added via chart.n_series.add().

Creating a Bar Chart

from aspose.cells_foss import Workbook

workbook = Workbook()
worksheet = workbook.worksheets[0]

# Write data
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
sales  = [100, 150, 120, 180, 200, 170]
for i, (m, s) in enumerate(zip(months, sales), 2):
    worksheet.cells[f"A{i}"].value = m
    worksheet.cells[f"B{i}"].value = s

# Add a bar chart anchored to rows 0-20, columns 4-12
chart = worksheet.charts.add_bar(0, 4, 20, 12)
chart.title = "Monthly Sales"
chart.n_series.add("B2:B7", category_data="A2:A7", name="Sales")

workbook.save("bar_chart.xlsx")

Creating a Line Chart

from aspose.cells_foss import Workbook

workbook = Workbook()
worksheet = workbook.worksheets[0]

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
sales  = [100, 150, 120, 180, 200, 170]
for i, (m, s) in enumerate(zip(months, sales), 2):
    worksheet.cells[f"A{i}"].value = m
    worksheet.cells[f"B{i}"].value = s

# Line chart anchored to rows 0-20, columns 4-12
chart = worksheet.charts.add_line(0, 4, 20, 12)
chart.title = "Monthly Sales"
chart.n_series.add("B2:B7", category_data="A2:A7", name="Sales")

workbook.save("line_chart.xlsx")

Key Highlights

  • 16 chart creation methods available; Line, Bar, Pie, Area, and Stock have full save support — other types can be created in memory but raise NotImplementedError on workbook.save()
  • Charts are positioned using a bounding box of zero-based row and column indices
  • Series data and category labels are specified using Excel-style range strings ("B2:B7")
  • No Microsoft Excel, COM automation, or native dependency is required

See Also