Class SparklineCollection

SparklineCollection class

Encapsulates a collection of Sparkline objects.

public class SparklineCollection : CollectionBase<Sparkline>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Gets the Sparkline element at the specified index.
Item { get; set; }

Methods

NameDescription
Add(string, int, int)Add a sparkline.
BinarySearch(Sparkline)
BinarySearch(Sparkline, IComparer<Sparkline>)
BinarySearch(int, int, Sparkline, IComparer<Sparkline>)
Clear()
Contains(Sparkline)
CopyTo(Sparkline[])
CopyTo(Sparkline[], int)
CopyTo(int, Sparkline[], int, int)
Exists(Predicate<Sparkline>)
Find(Predicate<Sparkline>)
FindAll(Predicate<Sparkline>)
FindIndex(Predicate<Sparkline>)
FindIndex(int, Predicate<Sparkline>)
FindIndex(int, int, Predicate<Sparkline>)
FindLast(Predicate<Sparkline>)
FindLastIndex(Predicate<Sparkline>)
FindLastIndex(int, Predicate<Sparkline>)
FindLastIndex(int, int, Predicate<Sparkline>)
GetEnumerator()
IndexOf(Sparkline)
IndexOf(Sparkline, int)
IndexOf(Sparkline, int, int)
LastIndexOf(Sparkline)
LastIndexOf(Sparkline, int)
LastIndexOf(Sparkline, int, int)
Remove(object)Removes the sparkline
RemoveAt(int)

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Charts;
    using System;

    public class SparklineCollectionDemo
    {
        public static void SparklineCollectionExample()
        {
            // Create a new workbook and get the first worksheet
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Insert sample data into the worksheet
            worksheet.Cells["A1"].PutValue(5);
            worksheet.Cells["B1"].PutValue(2);
            worksheet.Cells["C1"].PutValue(1);
            worksheet.Cells["D1"].PutValue(3);
            

            // Define the CellArea where the sparklines will be added
            CellArea cellArea = new CellArea { StartColumn = 4, EndColumn = 4, StartRow = 0, EndRow = 0 };

            // Add a new SparklineGroup to the worksheet
            int sparklineGroupIndex = worksheet.SparklineGroups.Add(SparklineType.Line, "A1:D1", false, cellArea);
            SparklineGroup sparklineGroup = worksheet.SparklineGroups[sparklineGroupIndex];

            SparklineCollection sparklineCollection = sparklineGroup.Sparklines;
            Console.WriteLine("Sparkline count: " + sparklineCollection.Count);

            // Add sparklines to the SparklineGroup
            sparklineCollection.Add("A1:D1", 0, 5);

            Console.WriteLine("Sparkline count: " + sparklineCollection.Count);

            // Set various properties for the SparklineGroup
            sparklineGroup.ShowHighPoint = true;
            sparklineGroup.ShowLowPoint = true;

            // Set colors for high and low points
            CellsColor highPointColor = workbook.CreateCellsColor();
            highPointColor.Color = System.Drawing.Color.Green;
            sparklineGroup.HighPointColor = highPointColor;

            CellsColor lowPointColor = workbook.CreateCellsColor();
            lowPointColor.Color = System.Drawing.Color.Red;
            sparklineGroup.LowPointColor = lowPointColor;

            // Set the series color and line weight
            CellsColor seriesColor = workbook.CreateCellsColor();
            seriesColor.Color = System.Drawing.Color.Orange;
            sparklineGroup.SeriesColor = seriesColor;
            sparklineGroup.LineWeight = 1.0;

            // Save the workbook
            workbook.Save("SparklineCollectionExample.xlsx");
        }
    }
}

See Also