Use the Excel Export API to Customize the Sparkline Appearance

  • 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.

Property Description
XlSparklineGroup.ColorMarker Gets or sets the color of the data markers for each sparkline in the sparkline group.
XlSparklineGroup.DisplayMarkers Gets or sets whether data markers are displayed for each sparkline in the sparkline group.
XlSparklineGroup.HighlightFirst Gets or sets whether the first data point in the sparkline should be colored differently.
XlSparklineGroup.ColorLast Gets or sets the color of the last data point for each sparkline in the sparkline group.
XlSparklineGroup.HighlightLast Gets or sets whether the last data point in the sparkline should be colored differently.
XlSparklineGroup.ColorHigh Gets or sets the color of the highest data point for each sparkline in the sparkline group.
XlSparklineGroup.HighlightHighest Gets or sets whether the highest data point in the sparkline should be colored differently.
XlSparklineGroup.ColorLow Gets or sets the color of the lowest data point for each sparkline in the sparkline group.
XlSparklineGroup.HighlightLowest Gets or sets whether the lowest data point in the sparkline should be colored differently.
XlSparklineGroup.ColorNegative Gets or sets the color of the negative data points for each sparkline in the sparkline group.
XlSparklineGroup.HighlightNegative Gets or sets whether negative data points in the sparkline should be colored differently.

Example

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