Version

Adding a Sparkline to a Worksheet (Infragistics Excel Engine)

Purpose

This topic demonstrates how to add sparklines to Excel® Worksheet (".xlsx), programmatically, using the Infragistics Excel Engine to show visual representations of data trends. Sparklines serve as quick and easy solution to visualize variations in your data. Sparklines are placed in cells that can be positioned anywhere within a worksheet and compliments the data it’s adjacent to.

Required background

NOTE: The XLSX format is required. Other formats are not supported at this time.

You need to first read the following topics:

Adding a Sparkline to an Excel Worksheet

Supported Sparklines

The following is a list of the supported predefined sparkline types.

SparklineType Looks like…​

Line

ExcelChart Sparkline Line.png

Column

ExcelChart Sparkline Column.png

Stacked

ExcelChart Sparkline Stacked.png

Introduction

Before adding a sparkline to a worksheet, a new SparklineGroup is required to be added to the Worksheet.SparklineGroups collection, via its Add method. The SparklineGroups' Add method takes in three required parameters that corresponds to the sparkline’s type, location, and data’s location.

Preview

Following is a preview of the final result of Sheet1: "Sparklines" displayed in Microsoft Excel 2016. The data is kept in Sheet2: "Data", with A1 through A10 made up of (4, 5, 2, 7, -1, 3, -2, 5, 2, and 6).

ExcelChart Sparklines.png

Code Snippets

In Visual Basic:

Dim workbook As Workbook = New Workbook(WorkbookFormat.Excel2007)
Dim sheet1 As Worksheet = workbook.Worksheets.Add("Sparklines")
Dim sheet2 As Worksheet = workbook.Worksheets.Add("Data")
sheet1.SparklineGroups.Add(SparklineType.Line, "Sparklines!A1:A1", "Data!A1:A10")
sheet1.SparklineGroups.Add(SparklineType.Column, "Sparklines!B1:B1", "Data!A1:A10")
sheet1.SparklineGroups.Add(SparklineType.Stacked, "Sparklines!C1:C1", "Data!A1:A10")

In C#:

Workbook workbook = new Workbook(WorkbookFormat.Excel2007);
Worksheet sheet1 = workbook.Worksheets.Add("Sparklines");
Worksheet sheet2 = workbook.Worksheets.Add("Data");
sheet1.SparklineGroups.Add(SparklineType.Line, "Sparklines!A1:A1", "Data!A1:A10");
sheet1.SparklineGroups.Add(SparklineType.Column, "Sparklines!B1:B1", "Data!A1:A10");
sheet1.SparklineGroups.Add(SparklineType.Stacked, "Sparklines!C1:C1", "Data!A1:A10");