officefileapi-113961-spreadsheet-document-api-examples-sparklines-how-to-create-sparklines.md
All sparklines in a worksheet are organized in groups. Each group can contain one or more sparklines of the same type that share identical formatting settings and axis scaling options. To create a new group of sparklines, get access to the worksheet’s SparklineGroupCollection collection using the Worksheet.SparklineGroups property, and then call the SparklineGroupCollection.Add method. Pass the following parameters.
To add a new sparkline to the existing group, access the collection of all sparklines contained in this group by using the SparklineGroup.Sparklines property, and call the SparklineCollection.Add method. This method allows you to define a cell at the intersection of the specified row and column where the new sparkline should be located and the cell range containing the source data for this sparkline.
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)
See Also
How to: Group and Ungroup Sparklines