Class TrendlineCollection

TrendlineCollection class

Represents a collection of all the Trendline objects for the specified data series.

public class TrendlineCollection : CollectionBase<Trendline>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Gets a Trendline object by its index.
Item { get; set; }

Methods

NameDescription
Add(TrendlineType)Adds a Trendline object to this collection with specified type.
Add(TrendlineType, string)Adds a Trendline object to this collection with specified type and name.
BinarySearch(Trendline)
BinarySearch(Trendline, IComparer<Trendline>)
BinarySearch(int, int, Trendline, IComparer<Trendline>)
Clear()
Contains(Trendline)
CopyTo(Trendline[])
CopyTo(Trendline[], int)
CopyTo(int, Trendline[], int, int)
Exists(Predicate<Trendline>)
Find(Predicate<Trendline>)
FindAll(Predicate<Trendline>)
FindIndex(Predicate<Trendline>)
FindIndex(int, Predicate<Trendline>)
FindIndex(int, int, Predicate<Trendline>)
FindLast(Predicate<Trendline>)
FindLastIndex(Predicate<Trendline>)
FindLastIndex(int, Predicate<Trendline>)
FindLastIndex(int, int, Predicate<Trendline>)
GetEnumerator()
IndexOf(Trendline)
IndexOf(Trendline, int)
IndexOf(Trendline, int, int)
LastIndexOf(Trendline)
LastIndexOf(Trendline, int)
LastIndexOf(Trendline, int, int)
RemoveAt(int)

Examples

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

    public class TrendlineCollectionDemo
    {
        public static void TrendlineCollectionExample()
        {
            // Instantiating a Workbook object
            Workbook workbook = new Workbook();
            
            // Adding a new worksheet to the Excel object
            int sheetIndex = workbook.Worksheets.Add();
            
            // Obtaining the reference of the newly added worksheet by passing its sheet index
            Worksheet worksheet = workbook.Worksheets[sheetIndex];
            
            // Adding sample values to cells
            worksheet.Cells["A1"].PutValue(50);
            worksheet.Cells["A2"].PutValue(100);
            worksheet.Cells["A3"].PutValue(150);
            worksheet.Cells["A4"].PutValue(200);
            worksheet.Cells["B1"].PutValue(60);
            worksheet.Cells["B2"].PutValue(32);
            worksheet.Cells["B3"].PutValue(50);
            worksheet.Cells["B4"].PutValue(40);

            // Adding a chart to the worksheet
            int chartIndex = workbook.Worksheets[0].Charts.Add(ChartType.Column, 3, 3, 15, 10);
            Chart chart = workbook.Worksheets[0].Charts[chartIndex];
            
            // Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
            chart.NSeries.Add("A1:A4", true);
            chart.NSeries.Add("B1:B4", true);
            
            // Adding a trendline to the first series
            int trendlineIndex = chart.NSeries[0].TrendLines.Add(TrendlineType.Linear, "MyTrendLine");
            Trendline trendline = chart.NSeries[0].TrendLines[trendlineIndex];
            
            // Setting trendline properties
            trendline.DisplayEquation = true;
            trendline.DisplayRSquared = true;
            trendline.Color = Color.Red;

            // Saving the Excel file
            workbook.Save("TrendlineCollectionExample.xlsx");
        }
    }
}

See Also