Back to Devexpress

How to: Delete Sparklines

officefileapi-113979-spreadsheet-document-api-examples-sparklines-how-to-delete-sparklines.md

latest4.5 KB
Original Source

How to: Delete Sparklines

  • Sep 19, 2023
  • 2 minutes to read

The examples below demonstrate how to remove sparkline groups or individual sparklines from a worksheet.

Delete a Sparkline Group

To remove a sparkline group, call the SparklineGroupCollection.Remove or SparklineGroupCollection.RemoveAt method of the SparklineGroupCollection object that is accessed from the Worksheet.SparklineGroups property.

csharp
SparklineGroupCollection sparklineGroups = worksheet.SparklineGroups;
// Create a line sparkline group.
SparklineGroup lineGroup = sparklineGroups.Add(worksheet["G4:G7"], worksheet["C4:F4,C5:F5,C6:F6,C7:F7"], SparklineGroupType.Line);
// Create a column sparkline group.
SparklineGroup columnGroup = sparklineGroups.Add(worksheet["G8"], worksheet["C8:F8"], SparklineGroupType.Column);

// Delete the line sparkline group from the collection.
sparklineGroups.RemoveAt(0);

// Delete the column sparkline group from the collection.
sparklineGroups.Remove(columnGroup);
vb
Dim sparklineGroups As SparklineGroupCollection = worksheet.SparklineGroups
' Create a line sparkline group. 
Dim lineGroup As SparklineGroup = sparklineGroups.Add(worksheet("G4:G7"), worksheet("C4:F4,C5:F5,C6:F6,C7:F7"), SparklineGroupType.Line)
' Create a column sparkline group. 
Dim columnGroup As SparklineGroup = sparklineGroups.Add(worksheet("G8"), worksheet("C8:F8"), SparklineGroupType.Column)

' Delete the line sparkline group from the collection. 
sparklineGroups.RemoveAt(0)

' Delete the column sparkline group from the collection. 
sparklineGroups.Remove(columnGroup)

You can also use the SparklineGroup.Delete method to delete the required sparkline group from the collection.

csharp
columnGroup.Delete();
vb
columnGroup.Delete()

To remove all sparkline groups from the worksheet at once, call the SparklineGroupCollection.Clear method.

csharp
sparklineGroups.Clear();
vb
sparklineGroups.Clear()

Delete a Single Sparkline

To remove an individual sparkline (defined by the Sparkline object) from a sparkline group, call the SparklineCollection.Remove or SparklineCollection.RemoveAt method of the SparklineCollection collection accessed from the SparklineGroup.Sparklines property of the SparklineGroup object that stores the sparkline you wish to delete.

You can also use the Sparkline.Delete method to delete the required sparkline from the sparkline collection.

csharp
// Create a group of line sparklines.
SparklineGroup lineGroup = worksheet.SparklineGroups.Add(worksheet["G4:G7"], worksheet["C4:F4,C5:F5,C6:F6,C7:F7"], SparklineGroupType.Line);

// Remove the first sparkline in the group.
lineGroup.Sparklines.RemoveAt(0);

// Remove the last sparkline in the group.
lineGroup.Sparklines[2].Delete();
vb
' Create a group of line sparklines.
Dim lineGroup As SparklineGroup = worksheet.SparklineGroups.Add(worksheet("G4:G7"), worksheet("C4:F4,C5:F5,C6:F6,C7:F7"), SparklineGroupType.Line)

' Remove the first sparkline in the group.
lineGroup.Sparklines.RemoveAt(0)

' Remove the last sparkline in the group.
lineGroup.Sparklines(2).Delete()

See Also

How to: Create Sparklines