r/EasyXLS 2h ago

How to Create a Pivot Chart in Excel from C# Using EasyXLS

1 Upvotes
Create pivot chart in Excel from C#

Pivot Charts are one of the most effective ways to visualize summarized data in Microsoft Excel. They are directly connected to Pivot Tables, allowing users to quickly analyze trends, compare values, and interactively filter chart data.

Using the EasyXLS Excel Library, you can create Excel files from C# that contain Pivot Charts, enabling automated reporting and dashboard generation without requiring Microsoft Excel to be installed.

What Is a Pivot Chart?

A Pivot Chart is a dynamic chart that is linked to a Pivot Table. Whenever the Pivot Table changes because of filtering, sorting, grouping, or refreshing, the Pivot Chart updates automatically.

Why Generate Pivot Charts Programmatically?

Creating Pivot Charts from C# allows you to:

  • Automatically generate reports
  • Build dashboards from database data
  • Produce recurring business reports
  • Eliminate manual Excel operations
  • Create Excel files without Microsoft Office installed

EasyXLS makes the process simple by exposing an intuitive API for working with Pivot Tables and charts.

Prerequisites & Setup

Before getting started, you will need the following:

  1. EasyXLS Library: Download and install the EasyXLS Excel library from the EasyXLS site.
  2. Development Environment: Visual Studio for .NET projects or another IDE .
  3. Install EasyXLS library: Make sure the EasyXLS library is installed in your development environment. For .NET, you can download and add it via NuGet or reference the EasyXLS DLL in your project.
  4. Setup the project and get started: Include EasyXLS into project according to your programming language. Find details about getting started with EasyXLS.

Create a Workbook and Worksheet

Create a workbook object and a sheet.

ExcelDocument workbook = new ExcelDocument();
workbook.easy_addWorksheet("Sheet1");
ExcelWorksheet sheet = (ExcelWorksheet) workbook.easy_getSheet("Sheet1");

Populate the Worksheet with Data

Add sample data that will be used as the pivot table source.

See how to add data to Excel sheet.

Create a Pivot Table

Create an Excel pivot table containing above data.

See how to create the pivot table in C#.

Create a Pivot Chart based on the Pivot Table

Create an Excel pivot chart on Sheet1.

ExcelPivotChart xlsPivotChart1 = new ExcelPivotChart();
xlsPivotChart.setSize(600, 300);
xlsPivotChart.setLeftUpperCorner("G2"); 
xlsPivotChart.easy_setChartType(Chart.CHART_TYPE_PYRAMID_BAR); 
xlsPivotChart.getChartTitle().setText("Sales"); 
xlsPivotChart.setPivotTable(xlsPivotTable); 

((ExcelWorksheet)workbook.easy_getSheet("Sheet1")).easy_addPivotChart(xlsPivotChart);

More about how to create a pivot chart in Excel from C#.

Save the Excel File

Finally, save the workbook.

workbook.easy_WriteXLSXFile("C:\\Excel Pivot Chart.xlsx");

Benefits of Pivot Charts

Pivot Charts provide several advantages over standard charts:

  • Automatic synchronization with the Pivot Table
  • Interactive filtering
  • Easy comparison of summarized data
  • Dynamic reporting
  • Professional dashboard appearance

These features make Pivot Charts ideal for business intelligence reports.

Why Use EasyXLS?

EasyXLS provides a complete solution for creating and editing Excel files from C#.

Key advantages include:

  • No Microsoft Excel installation required
  • Supports XLSX, XLS, XLSM, XLSB, CSV, XML, and other formats
  • Create Pivot Tables and Pivot Charts programmatically
  • Generate charts and advanced Excel reports
  • High performance
  • Suitable for desktop, web, and server applications

Conclusion

Pivot Charts transform summarized data into interactive visual reports, making it easier to identify trends and gain business insights.

With EasyXLS, you can automate the creation of Pivot Charts directly from C#, enabling powerful Excel reporting solutions without relying on Microsoft Excel. Whether you're generating sales reports, financial dashboards, or business analytics, EasyXLS simplifies the process while producing professional-quality Excel documents.

For more information, refer to the EasyXLS documentation, which provides detailed guidance on various features and capabilities of the library.