Create Excel Chart / Graph in C# and VB.NET

Create Excel Chart / Graph in C# and VB.NET with GemBox.Spreadsheet component.

GemBox.Spreadsheet is a C# / VB.NET component which provides simple and efficient way to read, write, convert and print native Microsoft Excel (XLSX, XLS) and other spreadsheet (ODS, CSV) formats and various document formats (HTML, PDF, XPS) from .NET applications without the need for Microsoft Excel on either the developer or client machines.
GemBox.Spreadsheet Free is free of charge while GemBox.Spreadsheet Professional is a commercial version licensed per developer.
For more information, see GemBox.Spreadsheet features and why GemBox.Spreadsheet outperforms Excel automation.

Following example creates Excel Chart / Graph.

C# code

// Create a new workbook and add a new worksheet to it.
var workbook = new ExcelFile();
var worksheet = workbook.Worksheets.Add("Chart");

// Add a new Column chart to the worksheet.
var chart = worksheet.Charts.Add(ChartType.Column, "K17", "R33");
// Select data for the chart.
chart.SelectData("A1:E5");

// TODO: populate cell range A1:E5 with data.

// Save workbook to XLSX and PDF formats.
workbook.Save("Chart.xlsx");
workbook.Save("Chart.pdf");

VB.NET code

' Create a new workbook and add a new worksheet to it.
Dim workbook = New ExcelFile()
Dim worksheet = workbook.Worksheets.Add("Chart")

' Add a new Column chart to the worksheet.
Dim chart = worksheet.Charts.Add(ChartType.Column, "K17", "R33")
' Select data for the chart.
chart.SelectData("A1:E5")

' TODO: populate cell range A1:E5 with data.

' Save workbook to XLSX and PDF formats.
workbook.Save("Chart.xlsx")
workbook.Save("Chart.pdf")