SeriesCollection

SeriesCollection class

Encapsulates a collection of Series objects.

class SeriesCollection;

Example

const { Workbook, ChartType, SaveFormat } = AsposeCells;

//Instantiating a Workbook object
var workbook = new Workbook();
//Adding a new worksheet to the Excel object
var sheetIndex = workbook.worksheets.add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
var worksheet = workbook.worksheets.get(sheetIndex);
//Adding a sample value to "A1" cell
worksheet.cells.get("A1").putValue(50);
//Adding a sample value to "A2" cell
worksheet.cells.get("A2").putValue(100);
//Adding a sample value to "A3" cell
worksheet.cells.get("A3").putValue(150);
//Adding a sample value to "A4" cell
worksheet.cells.get("A4").putValue(200);
//Adding a sample value to "B1" cell
worksheet.cells.get("B1").putValue(60);
//Adding a sample value to "B2" cell
worksheet.cells.get("B2").putValue(32);
//Adding a sample value to "B3" cell
worksheet.cells.get("B3").putValue(50);
//Adding a sample value to "B4" cell
worksheet.cells.get("B4").putValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.cells.get("C1").putValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.cells.get("C2").putValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.cells.get("C3").putValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.cells.get("C4").putValue("Y2");
//Adding a chart to the worksheet
var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
var chart = worksheet.charts.get(chartIndex);
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.nSeries.add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.nSeries.categoryData = "C1:C4";
//Saving the Excel file
var uint8Array = workbook.save(SaveFormat.Xlsx);

Properties

PropertyTypeDescription
categoryDatastringGets or sets the range of category Axis values. It can be a range of cells (such as, “d1:e10”), or a sequence of values (such as,"{2,6,8,10}").
secondCategoryDatastringGets or sets the range of second category Axis values. It can be a range of cells (such as, “d1:e10”), or a sequence of values (such as,"{2,6,8,10}"). Only effects when some ASerieses plot on the second axis.
isColorVariedbooleanRepresents if the color of points is varied.

Methods

MethodDescription
get(number)Gets the Series element at the specified index.
getSeriesByOrder(number)Gets the Series element by order.
removeAt(number)Remove at a series at the specific index.
changeSeriesOrder(number, number)Directly changes the orders of the two series.
swapSeries(number, number)Directly changes the orders of the two series.
setSeriesNames(number, string, boolean)Sets the name of all the serieses in the chart.
addR1C1(string, boolean)Adds the Series collection to a chart.
add(string, boolean)Adds the Series collection to a chart.
add(string, boolean, boolean)Adds the Series collection to a chart.
clear()Clears the collection
changeColors(ChartColorPaletteType)Set Monochromatic Palette for chart series.

categoryData

Gets or sets the range of category Axis values. It can be a range of cells (such as, “d1:e10”), or a sequence of values (such as,"{2,6,8,10}").

categoryData : string;

secondCategoryData

Gets or sets the range of second category Axis values. It can be a range of cells (such as, “d1:e10”), or a sequence of values (such as,"{2,6,8,10}"). Only effects when some ASerieses plot on the second axis.

secondCategoryData : string;

isColorVaried

Represents if the color of points is varied.

isColorVaried : boolean;

get(number)

Gets the Series element at the specified index.

get(index: number) : Series;

Parameters:

ParameterTypeDescription
indexnumberThe zero based index of the element.

Returns

The element at the specified index.

getSeriesByOrder(number)

Gets the Series element by order.

getSeriesByOrder(order: number) : Series;

Parameters:

ParameterTypeDescription
ordernumberThe order of series

Returns

The element series

removeAt(number)

Remove at a series at the specific index.

removeAt(index: number) : void;

Parameters:

ParameterTypeDescription
indexnumberThe index.

changeSeriesOrder(number, number)

Directly changes the orders of the two series.

changeSeriesOrder(sourceIndex: number, destIndex: number) : void;

Parameters:

ParameterTypeDescription
sourceIndexnumberThe current index
destIndexnumberThe dest index

Remarks

NOTE: This method is now obsolete. Instead, please use SeriesCollection.SwapSeries method. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.

swapSeries(number, number)

Directly changes the orders of the two series.

swapSeries(sourceIndex: number, destIndex: number) : void;

Parameters:

ParameterTypeDescription
sourceIndexnumberThe current index
destIndexnumberThe dest index

setSeriesNames(number, string, boolean)

Sets the name of all the serieses in the chart.

setSeriesNames(startIndex: number, area: string, isVertical: boolean) : void;

Parameters:

ParameterTypeDescription
startIndexnumberThe index of the first series which you want to set the name.
areastringSpecifies the area for the series name.
isVerticalboolean>Specifies whether to plot the series from a range of cell values by row or by column.

Remarks

br>If the start index is larger than the count of the serieses, it will return and do nothing.

If set data on contiguous cells, use colon to seperate them.For example, $C$2:$C$5.

If set data on contiguous cells, use comma to seperate them.For example, ($C$2,$D$5).</br

addR1C1(string, boolean)

Adds the Series collection to a chart.

addR1C1(area: string, isVertical: boolean) : number;

Parameters:

ParameterTypeDescription
areastringSpecifies values from which to plot the data series
isVerticalbooleanSpecifies whether to plot the series from a range of cell values by row or by column.

Returns

Return the first index of the added ASeries in the NSeries.

Remarks

br>If set data on contiguous cells, use colon to seperate them.For example, R[1]C[1]:R[3]C[2].

If set data on contiguous cells, use comma to seperate them.For example,(R[1]C[1],R[3]C[2]).</br

add(string, boolean)

Adds the Series collection to a chart.

add(area: string, isVertical: boolean) : number;

Parameters:

ParameterTypeDescription
areastringSpecifies values from which to plot the data series
isVerticalbooleanSpecifies whether to plot the series from a range of cell values by row or by column.

Returns

Return the first index of the added ASeries in the NSeries.

Remarks

br>If set data on contiguous cells, use colon to seperate them.For example, $C$2:$C$5.

If set data on non contiguous cells, use comma to seperate them.For example: ($C$2,$D$5).</br

add(string, boolean, boolean)

Adds the Series collection to a chart.

add(area: string, isVertical: boolean, checkLabels: boolean) : number;

Parameters:

ParameterTypeDescription
areastringSpecifies values from which to plot the data series
isVerticalbooleanSpecifies whether to plot the series from a range of cell values by row or by column.
checkLabelsbooleanIndicates whether the range contains series’s name

Returns

Return the first index of the added ASeries in the NSeries.

Remarks

br>If set data on contiguous cells, use colon to seperate them.For example, $C$2:$C$5.

If set data on non contiguous cells, use comma to seperate them.For example, ($C$2,$D$5).</br

clear()

Clears the collection

clear() : void;

changeColors(ChartColorPaletteType)

Set Monochromatic Palette for chart series.

changeColors(type: ChartColorPaletteType) : void;

Parameters:

ParameterTypeDescription
typeChartColorPaletteTypeThe Monochromatic Type.