Back to Devexpress

How to: Customize the Sparkline Appearance

windowsforms-120697-controls-and-libraries-spreadsheet-examples-sparklines-how-to-customize-the-sparkline-appearance.md

latest2.1 KB
Original Source

How to: Customize the Sparkline Appearance

  • Oct 29, 2020
  • 3 minutes to read

This topic demonstrates how to adjust the sparkline appearance.

  • Specify a sparkline color

  • Highlight data points

  • C#

  • VB.NET

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);

// Customize the group appearance.
// Set the sparkline color.
lineGroup.SeriesColor = Color.FromArgb(0x1F, 0x49, 0x7D);

// Set the sparkline weight.
lineGroup.LineWeight = 1.5;

// Display data markers on the sparklines and specify their color.
SparklinePoints points = lineGroup.Points;
points.Markers.IsVisible = true;
points.Markers.Color = Color.FromArgb(0x4B, 0xAC, 0xC6);

// Highlight the highest and lowest points on each sparkline in the group.
points.Highest.Color = Color.FromArgb(0xA9, 0xD6, 0x4F);
points.Lowest.Color = Color.FromArgb(0x80, 0x64, 0xA2);
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)

' Customize the group appearance.
' Set the sparkline color.
lineGroup.SeriesColor = Color.FromArgb(&H1F, &H49, &H7D)

' Set the sparkline weight.
lineGroup.LineWeight = 1.5

' Display data markers on the sparklines and specify their color.
Dim points As SparklinePoints = lineGroup.Points
points.Markers.IsVisible = True
points.Markers.Color = Color.FromArgb(&H4B, &HAC, &HC6)

' Highlight the highest and lowest points on each sparkline in the group.
points.Highest.Color = Color.FromArgb(&HA9, &HD6, &H4F)
points.Lowest.Color = Color.FromArgb(&H80, &H64, &HA2)

The following image shows sparkline charts created by the code above.

See Also

How to: Create Sparklines