Add, Delete and Manipulate Charts in Excel using C#

Charts are used to reflect information in easy to understand manner. Spreadsheets are used by almost all offices to manage data but they are not so easy to read. This is why a Chart, often known as a graph in Excel, is helpful to present an overview of the data. Aspose.Cells for Cloud API is rich with Chart manipulation APIs. In this article, we will be learning the following features:

A Chart in Excel using REST API

Aspose.Cells Cloud SDK for .NET provides the capabilities to create, edit and transform Excel files to PDF, CSV, HTML, and other supported formats within the .NET application. It also provides the feature to add a pivot chart, waterfall chart, clustered bar chart, timeline chart, and various other types. Now in order to use the SDK, the first step is the installation. So please visit the following link for more information on How to install Aspose.Cloud SDKs.

How to Add Chart in Excel

You can insert a chart or graph in an Excel workbook with Aspose.Cells Cloud API. Simply specify the necessary properties of the chart, like Chart Type, and Chart Area, and then make the API call. Below is a sample code that adds a Pie Chart to a worksheet:

This code snippet will create a chart as displayed in the following screenshot:

Add Chart in Excel

Delete Chart from Excel Spreadsheet

You can delete or remove an existing chart from an XLSX or XLS file with Aspose.Cells Cloud API. Simply specify the file name, worksheet name, and chart index. Subsequently, call the API and the respective chart will be deleted from the worksheet. However, the data will remain unaffected in the cells as it is, only the chart will be deleted. The following code snippet can be used for the same purpose:

The below screenshot shows the output worksheet where data stays the same and the chart is deleted.

Update Chart in Excel using C#

Since we have already considered two of the chart manipulation features above, let us check out another feature of updating an existing chart. Here we will be updating the title of the chart by specifying the name of the Excel file, name of the worksheet, and index of the chart as in the following C# code snippet:

The output of this code snippet can be observed in the screenshot below. The chart title is the same as specified by us.

These are a few of the many chart manipulation features offered by the API. You can sign up for free and test the APIs to their full capacity. In case of any query, please write to us at Free Support Forums.

Conclusion

In this article, we have learned the steps on how to add various types of charts in excel. The chart can be a pivot chart, an excel graph, sparklines excel, a stacked column chart, clustered bar chart, a waterfall graph, or clustered column chart excel. At the same time, we have also explored the options to programmatically edit or delete sparklines, bar stacked charts, or any other type using C# .NET code snippet. You may consider downloading the complete source code of Aspose.Cells Cloud SDK for .NET from GitHub and modify the code as per your requirements.

Related Articles

We highly recommend visiting the following links to learn more about