Visualizing grouped data in a compact, comparative way is a frequent requirement for business reports and dashboards. A Bar Stacked chart (also known as a stacked bar chart) lets you display multiple data series stacked horizontally, making it easy to see both totals and individual contributions. In this guide you will learn how to create a Bar Stacked chart in Excel using C# with Aspose.Cells for .NET. The provided code is fully functional and can be integrated into any .NET application.

This article covers the following topics:

C# Excel Library to Create Bar Stacked Charts

Aspose.Cells for .NET is a robust Excel manipulation library that enables developers to create, modify, and render Excel documents without requiring Microsoft Office. Its rich charting API supports every chart type available in Excel, including the Bar Stacked chart.

Key advantages of using Aspose.Cells:

  • Rich API Surface – Access every Excel feature programmatically.
  • High Performance – Process large workbooks with minimal memory footprint.
  • No COM/Interop Dependency – Works on any platform that supports .NET.
  • Multiple Output Formats – Save to XLSX, XLS, CSV, PDF, HTML, and image files.

Getting Started

  1. Download the latest release from the Aspose.Cells for .NET releases page.

  2. Install the NuGet package:

    PM> Install-Package Aspose.Cells
    
  3. Add a reference to Aspose.Cells in your project and start coding.

Create a Bar Stacked Chart in Excel using C#

Below is a complete, ready‑to‑run C# example that demonstrates how to:

  1. Create a new workbook.
  2. Populate sample data.
  3. Add a Bar Stacked chart.
  4. Customize series, axis titles, and chart appearance.
  5. Save the workbook to an XLSX file.

Explanation of the Code

StepWhat the code does
1Instantiates a new Workbook and selects the first worksheet (Sheet1).
2Populates the sheet with sample quarterly sales data for three products.
3Adds a BarStacked chart (ChartType.BarStacked). The chart area is defined by its top‑left and bottom‑right cell coordinates.
4Creates three data series, each pointing to a column of product sales. The true argument indicates that the series uses categories from the first column.
5Sets the category axis (horizontal axis) to the list of quarters (A2:A5).
6Demonstrates a few visual tweaks: custom plot‑area background, axis titles, and reduced gap width for a denser look.
7Saves the workbook as BarStackedChart_Output.xlsx in the application’s working folder.

Running the program will generate an Excel file containing a nicely formatted Bar Stacked chart that can be opened in Microsoft Excel, LibreOffice, or any compatible viewer.


Updating an Existing Bar Stacked Chart

If you need to modify a chart that already exists in a workbook (for example, changing series colors or adding a new series), the following snippet shows how to load a workbook, locate the chart, and apply updates.

This example demonstrates:

  • Loading an existing workbook.
  • Accessing and editing chart properties (title, series colors).
  • Adding a new data series on‑the‑fly.
  • Saving the modified workbook.

Get a Free License

Aspose.Cells offers a temporary free license that removes evaluation watermarks and unlocks full functionality for a limited period. Visit the Aspose temporary license page to request your license instantly. Apply the license at the start of your application:

Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense("Aspose.Total.NET.lic");

Bar Stacked Chart Excel: Free Resources

Continue your learning journey with these free resources:

Conclusion

In this article we demonstrated how to create and manipulate a Bar Stacked chart in Excel using C# and Aspose.Cells for .NET. The library provides a clean, high‑performance API that eliminates the need for Microsoft Office interop, making it ideal for server‑side automation, reporting solutions, and any .NET application that needs robust Excel charting capabilities.

Feel free to adapt the code samples to your own data sets, apply additional styling, or integrate the chart generation into larger workflows. For help, suggestions, or bug reports, join the Aspose.Cells support forum.

See Also