How to Create and Edit Excel Charts in C#

How to Create and Edit Excel Charts in C#

IronXL enables C# developers to create, edit, and remove Excel charts programmatically using simple API calls. You can generate column, line, pie, and other chart types directly from your data without Excel Interop dependencies.

In Excel, a chart is a graphical representation of data used to display and analyze information visually. Excel provides various chart types, such as bar charts, line charts, and pie charts, each suited for different data and analysis needs. When working with IronXL's comprehensive Excel library, you can programmatically create these visualizations to enhance your reports and dashboards.

Quickstart: Create and Plot a Line Chart in Seconds

With IronXL, you can install, load a workbook, call CreateChart, add your data series, set your title and legend position, and Plot—all in just a few lines. This example shows how to create a chart using native C# methods without Interop overhead.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    // Load workbook and create a line chart with data series
    var chart = workSheet.CreateChart(ChartType.Line, 2, 2, 15, 10).AddSeries("A2:A10","B2:B10").Title = workSheet["B1"].StringValue; 
    // Set title and legend position, then plot the chart
    chart.SetTitle("Quick Line Chart").SetLegendPosition(LegendPosition.Bottom).Plot();
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer


Get started with IronXL


How Do I Create Charts in Excel?

IronXL supports column, scatter, line, pie, bar, and area charts. To create a chart, specify the following components. This flexibility allows you to create Excel spreadsheets with rich visualizations tailored to your data presentation needs.

  1. Use CreateChart to specify the chart type and worksheet location.
  2. Add series with AddSeries. This method accepts a single column for some chart types. The first parameter is horizontal axis values. The second is vertical axis values.
  3. Optionally specify series name, chart name, and legend position.
  4. Call Plot to render the chart. Multiple calls create multiple charts.

Let's create charts from the data in the chart.xlsx Excel file. A preview of the data is displayed below:

Spreadsheet with sample chart data showing monthly animal counts for giraffes, elephants, and rhinos from Jan-Jun

What's the Process for Creating Column Charts?

Column charts are ideal for comparing values across categories. When you load spreadsheet data, you can visualize it effectively using column charts to highlight differences between data points. The following example demonstrates creating a multi-series column chart with animal population data:

:path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-column-chart.cs
using IronXL;
using IronXL.Drawing.Charts;

WorkBook workBook = WorkBook.Load("chart.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Set the chart type and position
IChart chart = workSheet.CreateChart(ChartType.Column, 5, 5, 20, 10);

string xAxis = "A2:A7";

// Add the series
IChartSeries series = chart.AddSeries(xAxis, "B2:B7");
series.Title = workSheet["B1"].StringValue;

// Add the series
series = chart.AddSeries(xAxis, "C2:C7");
series.Title = workSheet["C1"].StringValue;

// Add the series
series = chart.AddSeries(xAxis, "D2:D7");
series.Title = workSheet["D1"].StringValue;

// Set the chart title
chart.SetTitle("Column Chart");

// Set the legend position
chart.SetLegendPosition(LegendPosition.Bottom);

// Plot the chart
chart.Plot();

workBook.SaveAs("columnChart.xlsx");
$vbLabelText   $csharpLabel
Excel spreadsheet showing animal data table and corresponding grouped column chart with monthly counts for giraffes, elephants, and rhinos

How Do I Create Line Charts?

Line charts excel at showing trends over time. Since line charts display the same information as column charts, switching between them requires only changing the chart type. This makes line charts particularly useful when reading XLSX files containing time-series data:

:path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-pie-chart.cs
using IronXL;
using IronXL.Drawing.Charts;

WorkBook workBook = WorkBook.Load("chart.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Set the chart type and position
IChart chart = workSheet.CreateChart(ChartType.Pie, 5, 5, 20, 10);

string xAxis = "A2:A7";

// Add the series
IChartSeries series = chart.AddSeries(xAxis, "B2:B7");
series.Title = workSheet["B1"].StringValue;

// Set the chart title
chart.SetTitle("Pie Chart");

// Set the legend position
chart.SetLegendPosition(LegendPosition.Bottom);

// Plot the chart
chart.Plot();

workBook.SaveAs("pieChart.xlsx");
$vbLabelText   $csharpLabel
Excel spreadsheet showing animal data table and corresponding line chart with three trend lines for giraffes, elephants, and rhinos

When Should I Use Pie Charts?

Pie charts show proportions and percentages of a whole. For pie charts, only one column of data is needed, making them simpler to implement. They're effective when you want to convert spreadsheet data into visual representations of market share, budget allocation, or category distribution:

:path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-pie-chart.cs
using IronXL;
using IronXL.Drawing.Charts;

WorkBook workBook = WorkBook.Load("chart.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Set the chart type and position
IChart chart = workSheet.CreateChart(ChartType.Pie, 5, 5, 20, 10);

string xAxis = "A2:A7";

// Add the series
IChartSeries series = chart.AddSeries(xAxis, "B2:B7");
series.Title = workSheet["B1"].StringValue;

// Set the chart title
chart.SetTitle("Pie Chart");

// Set the legend position
chart.SetLegendPosition(LegendPosition.Bottom);

// Plot the chart
chart.Plot();

workBook.SaveAs("pieChart.xlsx");
$vbLabelText   $csharpLabel
Spreadsheet with wildlife data and pie chart showing monthly giraffe distribution, April highlighted with 89 giraffes (21%)

How Do I Edit Existing Charts?

When working with existing Excel files, you may need to modify charts already created. IronXL provides straightforward methods to edit existing charts, allowing you to update titles, reposition legends, and refresh data. This is useful when editing Excel files that contain pre-existing visualizations.

You can edit legend position and chart title in existing charts. To edit a chart, first retrieve it by accessing the Charts property and selecting the targeted chart. Then access the chart properties to make your edits:

:path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-edit-chart.cs
using IronXL;
using IronXL.Drawing.Charts;

WorkBook workBook = WorkBook.Load("pieChart.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Retrieve the chart
IChart chart = workSheet.Charts[0];

// Edit the legend position
chart.SetLegendPosition(LegendPosition.Top);

// Edit the chart title
chart.SetTitle("Edited Chart");

workBook.SaveAs("editedChart.xlsx");
$vbLabelText   $csharpLabel
Pie chart showing monthly data from Jan-Jun with color-coded segments and legend below
Pie chart showing monthly data distribution from January to June with color-coded segments and legend

How Do I Remove Charts from Excel?

Sometimes you need to clean up Excel files by removing outdated or unnecessary charts. This is common when managing worksheets containing multiple visualizations. To remove an existing chart from a spreadsheet, first retrieve the chart from the Charts property. You'll receive a list of charts. Pass the targeted chart object to RemoveChart:

:path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-remove-chart.cs
using IronXL;
using IronXL.Drawing.Charts;
using System.Collections.Generic;

WorkBook workBook = WorkBook.Load("pieChart.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Retrieve the chart
List<IChart> chart = workSheet.Charts;

// Remove the chart
workSheet.RemoveChart(chart[0]);

workBook.SaveAs("removedChart.xlsx");
$vbLabelText   $csharpLabel

Advanced Chart Customization

Beyond basic chart creation, IronXL supports advanced customization options. When creating complex reports or dashboards, you can combine charts with other Excel features like conditional formatting to create comprehensive data visualizations.

For business applications, charts often need dynamic generation from database queries or real-time data sources. IronXL integrates seamlessly with .NET data structures, allowing you to create charts from DataTables, Lists, or any enumerable collection. This makes it ideal for generating automated reports that include visual elements.

Summary

IronXL provides a complete solution for working with Excel charts in C# applications. Whether creating new visualizations, modifying existing ones, or removing outdated charts, the library offers intuitive methods that don't require Excel Interop. By combining chart functionality with IronXL's other features like data manipulation and formatting, you can build sophisticated Excel automation solutions that enhance data presentation and analysis in your .NET applications.

Frequently Asked Questions

How can I create Excel charts programmatically in C# without using Interop?

IronXL provides a simple API to create Excel charts in C# without Interop dependencies. You can use the CreateChart method to specify chart type and position, AddSeries to add data, and Plot to render the chart - all through native C# code.

What types of charts can I create in Excel spreadsheets using C#?

IronXL supports creating various chart types including column, scatter, line, pie, bar, and area charts. You can specify the chart type when calling the CreateChart method and customize each chart with titles, legends, and data series.

How do I add data series to an Excel chart programmatically?

Use IronXL's AddSeries method to add data to your charts. This method accepts cell ranges as parameters - the first parameter for horizontal axis values and the second for vertical axis values. You can add multiple series to create multi-series charts.

What's the quickest way to create a line chart in Excel using C#?

With IronXL, you can create a line chart in just a few lines of code: use CreateChart(ChartType.Line) to initialize the chart, AddSeries() to add your data ranges, SetTitle() for the chart title, and Plot() to render it on the worksheet.

Can I customize chart properties like title and legend position?

Yes, IronXL allows full customization of Excel charts. You can use SetTitle() to add chart titles, SetLegendPosition() to place the legend (top, bottom, left, right), and optionally specify series names for better data identification.

Do I need Microsoft Excel installed to create charts programmatically?

No, IronXL works independently without requiring Microsoft Excel installation. It handles all Excel file operations and chart creation internally, making it ideal for server environments and applications where Excel cannot be installed.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
Ready to Get Started?
Nuget Downloads 1,780,288 | Version: 2025.12 just released