officefileapi-devexpress-dot-spreadsheet-dot-sparklinecollection-dot-add-x28-system-dot-int32-system-dot-int32-devexpress-dot-spreadsheet-dot-cellrange-x29.md
Creates a new sparkline and adds it to the collection.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
Sparkline Add(
int rowIndex,
int columnIndex,
CellRange dataRange
)
Function Add(
rowIndex As Integer,
columnIndex As Integer,
dataRange As CellRange
) As Sparkline
| Name | Type | Description |
|---|---|---|
| rowIndex | Int32 |
An integer that is the zero-based index of the row where the new sparkline should be located.
| | columnIndex | Int32 |
An integer that is the zero-based index of the column where the new sparkline should be located.
| | dataRange | CellRange |
A CellRange object that contains the source data for the sparkline.
|
| Type | Description |
|---|---|
| Sparkline |
A Sparkline object that specifies the new sparkline.
|
All sparklines in a worksheet are organized in groups. Each sparkline group includes one or more sparklines stored within the SparklineCollection collection accessible using the SparklineGroup.Sparklines property.
The following code snippet uses the collection’s Add method to add a new sparkline to the existing sparkline group:
Worksheet worksheet = workbook.Worksheets["SparklineExamples"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a group of line sparklines.
SparklineGroup quarterlyGroup = worksheet.SparklineGroups.Add(worksheet["G4:G6"], worksheet["C4:F4,C5:F5,C6:F6"], SparklineGroupType.Line);
// Add one more sparkline to the existing group.
quarterlyGroup.Sparklines.Add(6, 6, worksheet["C7:F7"]);
// Display a column sparkline in the total cell.
SparklineGroup totalGroup = worksheet.SparklineGroups.Add(worksheet["G8"], worksheet["C8:F8"], SparklineGroupType.Column);
Dim worksheet As Worksheet = workbook.Worksheets("SparklineExamples")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a group of line sparklines.
Dim quarterlyGroup As SparklineGroup = worksheet.SparklineGroups.Add(worksheet("G4:G6"), worksheet("C4:F4,C5:F5,C6:F6"), SparklineGroupType.Line)
' Add one more sparkline to the existing group.
quarterlyGroup.Sparklines.Add(6, 6, worksheet("C7:F7"))
' Display a column sparkline in the total cell.
Dim totalGroup As SparklineGroup = worksheet.SparklineGroups.Add(worksheet("G8"), worksheet("C8:F8"), SparklineGroupType.Column)
To remove a sparkline from the collection, use the SparklineCollection.Remove or SparklineCollection.RemoveAt method.
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Add(Int32, Int32, CellRange) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
// Add one more sparkline to the existing group.
quarterlyGroup.Sparklines.Add(6, 6, worksheet["C7:F7"]);
' Add one more sparkline to the existing group.
quarterlyGroup.Sparklines.Add(6, 6, worksheet("C7:F7"))
See Also