Insert Sparkline
Contents
[
Hide
]
Insert a sparkline
Sparkline is a tiny chart in a worksheet cell that provides a visual representation of data. Use sparklines to show trends in a series of values, such as seasonal increases or decreases, economic cycles, or to highlight maximum and minimum values. Position a sparkline near its data for greatest impact.There are three types of Sparkline: Line, Column and Stacked.
It’s simple to create a sparkline with Aspose.Cells for Python via .NET with the following example codes:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import CellArea, Workbook | |
from aspose.cells.charts import SparklineType | |
from aspose.pydrawing import Color | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Instantiating a Workbook object | |
book = Workbook() | |
sheet = book.worksheets[0] | |
sheet.cells.get("A1").put_value(5) | |
sheet.cells.get("B1").put_value(2) | |
sheet.cells.get("C1").put_value(1) | |
sheet.cells.get("D1").put_value(3) | |
# Define the CellArea | |
ca = CellArea() | |
ca.start_column = 4 | |
ca.end_column = 4 | |
ca.start_row = 0 | |
ca.end_row = 0 | |
idx = sheet.sparkline_groups.add(SparklineType.LINE, sheet.name + "!A1:D1", False, ca) | |
group = sheet.sparkline_groups[idx] | |
group.sparklines.add(sheet.name + "!A1:D1", 0, 4) | |
#region Customize Sparklines | |
# Create CellsColor | |
clr = book.create_cells_color() | |
clr.color = Color.orange | |
group.series_color = clr | |
# set the high points are colored green and the low points are colored red | |
group.show_high_point = True | |
group.show_low_point = True | |
group.high_point_color.color = Color.green | |
group.low_point_color.color = Color.red | |
# set line weight | |
group.line_weight = 1.0 | |
# you also can choose a nice visual style | |
# group.PresetStyle = SparklinePresetStyleType.Style10; | |
#endregion Customize Sparklines | |
# Saving the Excel file | |
book.save(dataDir + "output.xlsx") |