Sparkline
Source: aspose.
A sparkline represents a tiny chart or graphic in a worksheet cell that provides a visual representation of data. Example: [C#] Workbook book = new Workbook(); Worksheet sheet = book.Worksheets[0]; sheet.Cells["A1"].PutValue(5); sheet.Cells["B1"].PutValue(2); sheet.Cells["C1"].PutValue(1); sheet.Cells["D1"].PutValue(3); // Define the CellArea CellArea ca = new CellArea(); ca.StartColumn = 4; ca.EndColumn = 4; ca.StartRow = 0; ca.EndRow = 0; int idx = sheet.SparklineGroupCollection.Add(Aspose.Cells.Charts.SparklineType.Line, sheet.Name + "!A1:D1", false, ca); SparklineGroup group = sheet.SparklineGroupCollection[idx]; idx = group.SparklineCollection.Add(sheet.Name + "!A1:D1", 0, 4); Sparkline line = group.SparklineCollection[idx]; Console.WriteLine($"Saprkline data range:{line.DataRange}, row:{line.Row}, column:{line.Column}"); line.ToImage("output.png", new ImageOrPrintOptions());
Methods
toImageStream(sparkline, stream, options)
Converts a sparkline to an image.
Example
var aspose = aspose || {};
aspose.cells = require("aspose.cells");
var fs = require("fs");
var workbook = new aspose.cells.Workbook("sparkline.xlsx");
var sparkline = workbook.getWorksheets().get(0).getSparklineGroupCollection().get(0).getSparklineCollection().get(0);
var imgWriteStream = fs.createWriteStream("sparkline.jpeg");
var imgOptions = new aspose.cells.ImageOrPrintOptions();
imgOptions.setHorizontalResolution(200);
imgOptions.setVerticalResolution(300);
imgOptions.setImageFormat(aspose.cells.ImageFormat.getJpeg());
aspose.cells.Sparkline.toImageStream(sparkline, imgWriteStream, imgOptions);
Parameters
Name | Type | Optional | Description |
---|---|---|---|
sparkline |
|
The Sparkline object |
|
stream |
WritableStream |
|
The stream of the output image |
options |
|
Addtional image creation options |
getColumn()
Gets the column index of the sparkline.
getDataRange()
Represents the data range of the sparkline.
getRow()
Gets the row index of the sparkline.
setDataRange()
Represents the data range of the sparkline.
toImage(fileName, options)
Converts a sparkline to an image.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
fileName |
String |
|
The image file name. |
options |
|
The image options |
toImage(stream, options)
Converts a sparkline to an image.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
stream |
OutputStream |
|
The image stream. |
options |
|
The image options. |