Work With Charts Python

Work With Charts Python

This guide shows how to work with charts python using Aspose.Slides FOSS for Python.


Prerequisites

RequirementDetail
RuntimePython
Packageaspose-slides-foss
InstallSee the Installation guide

Steps

  1. Install the package:
pip install aspose-slides-foss
  1. Use the Chart class for the core operation.
import aspose.slides_foss as slides
from aspose.slides_foss.charts import ChartType
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    slide = prs.slides[0]
    chart = slide.shapes.add_chart(ChartType.CLUSTERED_COLUMN, 100, 100, 500, 400)

    # add_chart() seeds the chart with sample series/category data
    series = chart.chart_data.series[0]
    print(f"Series: {series.name.as_literal_string}, {len(series.data_points)} point(s)")

    prs.save("chart.pptx", SaveFormat.PPTX)

Tips and Best Practices

  • Check the API reference for the latest class signatures
  • Handle file I/O exceptions when reading or writing files
  • Dispose of resources properly after use

Related Resources

See Also

 English