Class ChartCollection

ChartCollection class

Encapsulates a collection of Chart objects.

public class ChartCollection : CollectionBase<Chart>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Gets the Chart element at the specified index. (2 indexers)
Item { get; set; }

Methods

NameDescription
Add(ChartType, int, int, int, int)Adds a chart to the collection.
Add(ChartType, string, int, int, int, int)(Obsolete.) Adds a chart to the collection.
Add(byte[], string, bool, int, int, int, int)Adds a chart with preset template.
Add(ChartType, string, bool, int, int, int, int)Adds a chart to the collection.
AddFloatingChart(ChartType, int, int, int, int)Adds a chart to the collection.
BinarySearch(Chart)
BinarySearch(Chart, IComparer<Chart>)
BinarySearch(int, int, Chart, IComparer<Chart>)
Clear()Clear all charts. (2 methods)
Contains(Chart)
CopyTo(Chart[])
CopyTo(Chart[], int)
CopyTo(int, Chart[], int, int)
Exists(Predicate<Chart>)
Find(Predicate<Chart>)
FindAll(Predicate<Chart>)
FindIndex(Predicate<Chart>)
FindIndex(int, Predicate<Chart>)
FindIndex(int, int, Predicate<Chart>)
FindLast(Predicate<Chart>)
FindLastIndex(Predicate<Chart>)
FindLastIndex(int, Predicate<Chart>)
FindLastIndex(int, int, Predicate<Chart>)
GetEnumerator()
IndexOf(Chart)
IndexOf(Chart, int)
IndexOf(Chart, int, int)
LastIndexOf(Chart)
LastIndexOf(Chart, int)
LastIndexOf(Chart, int, int)
RemoveAt(int)Remove a chart at the specific index. (2 methods)

Examples

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

    public class ChartCollectionDemo
    {
        public static void ChartCollectionExample()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Add some sample data to the worksheet
            worksheet.Cells[0, 0].PutValue("Category");
            worksheet.Cells[0, 1].PutValue("Value");
            worksheet.Cells[1, 0].PutValue("A");
            worksheet.Cells[1, 1].PutValue(10);
            worksheet.Cells[2, 0].PutValue("B");
            worksheet.Cells[2, 1].PutValue(20);
            worksheet.Cells[3, 0].PutValue("C");
            worksheet.Cells[3, 1].PutValue(30);

            // Access the chart collection of the worksheet
            ChartCollection charts = worksheet.Charts;

            // Add a chart to the worksheet
            int chartIndex = charts.Add(ChartType.Column, 5, 0, 15, 5);
            Chart chart = charts[chartIndex];

            // Set the data range for the chart
            chart.SetChartDataRange("A1:B4", true);

            // Customize the chart
            chart.Title.Text = "Sample Chart";
            chart.ShowLegend = true;

            // Save the workbook
            workbook.Save("ChartCollectionExample.xlsx");
            workbook.Save("ChartCollectionExample.pdf");
        }
    }
}

See Also