Back to Devexpress

Use the Excel Export API to Customize the Sparkline Appearance

officefileapi-116997-excel-export-library-sparklines-how-to-customize-the-sparkline-appearance.md

latest4.9 KB
Original Source

Use the Excel Export API to Customize the Sparkline Appearance

  • Sep 19, 2023
  • 3 minutes to read

Specify a Series Color

To specify a color used to draw a series in each sparkline in the sparkline group, use the XlSparklineGroup.ColorSeries property. If sparklines are of the Line type (the XlSparklineGroup.SparklineType property is equal to the XlSparklineType.Line value) you can also set the line weight using the XlSparklineGroup.LineWeight property.

Highlight Data Points

You can highlight important data points on a sparkline by displaying and coloring markers on line sparklines, or by differentiating points by color on column and win/loss sparklines.

The table below lists the sparkline group properties used to highlight specific points on each sparkline in the sparkline group.

PropertyDescription
XlSparklineGroup.ColorMarkerGets or sets the color of the data markers for each sparkline in the sparkline group.
XlSparklineGroup.DisplayMarkersGets or sets whether data markers are displayed for each sparkline in the sparkline group.
XlSparklineGroup.HighlightFirstGets or sets whether the first data point in the sparkline should be colored differently.
XlSparklineGroup.ColorLastGets or sets the color of the last data point for each sparkline in the sparkline group.
XlSparklineGroup.HighlightLastGets or sets whether the last data point in the sparkline should be colored differently.
XlSparklineGroup.ColorHighGets or sets the color of the highest data point for each sparkline in the sparkline group.
XlSparklineGroup.HighlightHighestGets or sets whether the highest data point in the sparkline should be colored differently.
XlSparklineGroup.ColorLowGets or sets the color of the lowest data point for each sparkline in the sparkline group.
XlSparklineGroup.HighlightLowestGets or sets whether the lowest data point in the sparkline should be colored differently.
XlSparklineGroup.ColorNegativeGets or sets the color of the negative data points for each sparkline in the sparkline group.
XlSparklineGroup.HighlightNegativeGets or sets whether negative data points in the sparkline should be colored differently.

Example

View Example

csharp
// Create a sparkline group.
XlSparklineGroup group = new XlSparklineGroup(XlCellRange.FromLTRB(1, 1, 8, 6), XlCellRange.FromLTRB(9, 1, 9, 6));
// Change the sparkline group type to "Column".
group.SparklineType = XlSparklineType.Column;
// Set the series color.
group.ColorSeries = XlColor.FromTheme(XlThemeColor.Accent1, 0.0);
// Set the color for negative points on sparklines. 
group.ColorNegative = XlColor.FromTheme(XlThemeColor.Accent2, 0.0);
// Set the color for the highest points on sparklines.
group.ColorHigh = XlColor.FromTheme(XlThemeColor.Accent6, 0.0);
// Highlight the highest and negative points on each sparkline in the group.
group.HighlightNegative = true;
group.HighlightHighest = true;
sheet.SparklineGroups.Add(group);
vb
' Create a sparkline group.
Dim group As New XlSparklineGroup(XlCellRange.FromLTRB(1, 1, 8, 6), XlCellRange.FromLTRB(9, 1, 9, 6))
' Change the sparkline group type to "Column".
group.SparklineType = XlSparklineType.Column
' Set the series color.
group.ColorSeries = XlColor.FromTheme(XlThemeColor.Accent1, 0.0)
' Set the color for negative points on sparklines. 
group.ColorNegative = XlColor.FromTheme(XlThemeColor.Accent2, 0.0)
' Set the color for the highest points on sparklines.
group.ColorHigh = XlColor.FromTheme(XlThemeColor.Accent6, 0.0)
' Highlight the highest and negative points on each sparkline in the group.
group.HighlightNegative = True
group.HighlightHighest = True
sheet.SparklineGroups.Add(group)