Back to Devexpress

SparklineCollection.Add(Int32, Int32, CellRange) Method

officefileapi-devexpress-dot-spreadsheet-dot-sparklinecollection-dot-add-x28-system-dot-int32-system-dot-int32-devexpress-dot-spreadsheet-dot-cellrange-x29.md

latest5.7 KB
Original Source

SparklineCollection.Add(Int32, Int32, CellRange) Method

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

Declaration

csharp
Sparkline Add(
    int rowIndex,
    int columnIndex,
    CellRange dataRange
)
vb
Function Add(
    rowIndex As Integer,
    columnIndex As Integer,
    dataRange As CellRange
) As Sparkline

Parameters

NameTypeDescription
rowIndexInt32

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.

|

Returns

TypeDescription
Sparkline

A Sparkline object that specifies the new sparkline.

|

Remarks

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:

View Example

csharp
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);
vb
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.

spreadsheet-document-api-chart-examples/CS/SpreadsheetDocServerChartAPISamples/CodeExamples/SparklineActions.cs#L23

csharp
// Add one more sparkline to the existing group.
quarterlyGroup.Sparklines.Add(6, 6, worksheet["C7:F7"]);

spreadsheet-document-api-chart-examples/VB/SpreadsheetDocServerChartAPISamples/CodeExamples/SparklineActions.vb#L23

vb
' Add one more sparkline to the existing group.
quarterlyGroup.Sparklines.Add(6, 6, worksheet("C7:F7"))

See Also

Spreadsheet Document API Examples

SparklineCollection Interface

SparklineCollection Members

DevExpress.Spreadsheet Namespace