# GC.Spread.Sheets.Charts.ChartCollection

## Content

# Class: ChartCollection

[Sheets](../modules/GC.Spread.Sheets).[Charts](../modules/GC.Spread.Sheets.Charts).ChartCollection

## Table of contents

### Constructors

- [constructor](GC.Spread.Sheets.Charts.ChartCollection#constructor)

### Methods

- [add](GC.Spread.Sheets.Charts.ChartCollection#add)
- [all](GC.Spread.Sheets.Charts.ChartCollection#all)
- [clear](GC.Spread.Sheets.Charts.ChartCollection#clear)
- [get](GC.Spread.Sheets.Charts.ChartCollection#get)
- [preserveUnsupportedChart](GC.Spread.Sheets.Charts.ChartCollection#preserveunsupportedchart)
- [remove](GC.Spread.Sheets.Charts.ChartCollection#remove)
- [zIndex](GC.Spread.Sheets.Charts.ChartCollection#zindex)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new ChartCollection**()

Represents a chart manager that managers all charts in a sheet.

## Methods

### <a id="add" name="add"></a> add

▸ **add**(`name`, `chartType`, `x`, `y`, `width`, `height`, `dataRange?`, `dataOrientation?`, `colorScheme?`): [`Chart`](GC.Spread.Sheets.Charts.Chart)

Adds a chart to the sheet.

**`example`**
```
//This example shows how to add a chart.
var dataRange = "A1:D4";
var chart = activeSheet.charts.add('Chart1', GC.Spread.Sheets.Charts.ChartType.columnClustered, 250, 20, 600, 400, dataRange);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the chart that will be added to the sheet. |
| `chartType` | [`ChartType`](../enums/GC.Spread.Sheets.Charts.ChartType) | The type of the chart. |
| `x` | `number` | The x location of the chart. |
| `y` | `number` | The y location of the chart. |
| `width` | `number` | The width of the chart. |
| `height` | `number` | The height of the chart. |
| `dataRange?` | `string` | The formula string of data range for the chart. |
| `dataOrientation?` | [`RowCol`](../enums/GC.Spread.Sheets.Charts.RowCol) | The orientation of data for series. |
| `colorScheme?` | [`ColorScheme`](../modules/GC.Spread.Sheets.Charts#colorscheme) | - |

#### Returns

[`Chart`](GC.Spread.Sheets.Charts.Chart)

The chart that has been added to the sheet.

___

### <a id="all" name="all"></a> all

▸ **all**(): [`Chart`](GC.Spread.Sheets.Charts.Chart)[]

Gets all of the charts in the sheet.

**`example`**
```
var dataRange = "A1:D4";
activeSheet.charts.add('Chart1', GC.Spread.Sheets.Charts.ChartType.columnClustered, 250, 20, 600, 180, dataRange);
var dataRange2 = "A20:D24";
activeSheet.charts.add('Chart2', GC.Spread.Sheets.Charts.ChartType.columnClustered, 250, 220, 600, 180, dataRange2);
var charts = activeSheet.charts.all();
for (var i = 0; i &lt; charts.length; i++) {
    alert("Name of chart " + i + " is:  " + charts[i].name())
}
```

#### Returns

[`Chart`](GC.Spread.Sheets.Charts.Chart)[]

The collection of all the charts in the sheet.

___

### <a id="clear" name="clear"></a> clear

▸ **clear**(): `void`

Removes all charts in the sheet.

#### Returns

`void`

___

### <a id="get" name="get"></a> get

▸ **get**(`name`): [`Chart`](GC.Spread.Sheets.Charts.Chart)

Gets a chart from the sheet by the indicate name.

**`example`**
```
var dataRange = "A1:D4";
activeSheet.charts.add('Chart1', GC.Spread.Sheets.Charts.ChartType.columnClustered, 250, 20, 600, 400, dataRange);
//button
$("#button1").click(function () {
 var chart = activeSheet.charts.get("f2");
});
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the chart. |

#### Returns

[`Chart`](GC.Spread.Sheets.Charts.Chart)

The chart in the sheet with the indicate name.

___

### <a id="preserveunsupportedchart" name="preserveunsupportedchart"></a> preserveUnsupportedChart

▸ **preserveUnsupportedChart**(`flag?`, `paintCallBack?`): `undefined` \| `boolean`

Gets or sets if preserve unsupport chart when import.

**`example`**
```
sheet.charts.preserveUnsupportedChart(true, function(chart, ctx, width, height){
    ctx.textBaseline = 'middle';
    ctx.textAlign = 'center';
    ctx.fillStyle = '#000000';
    ctx.fillText("to be continue", width / 2, height / 2, width);
})
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `flag?` | `boolean` | indicates whether preserve unsupport chart when import, the default value is false, if set true, it will be painted as paintCallBack. |
| `paintCallBack?` | [`ILegacyChartPaintCallBack`](../interfaces/GC.Spread.Sheets.Charts.ILegacyChartPaintCallBack) \| [`IPaintCallBack`](../interfaces/GC.Spread.Sheets.Charts.IPaintCallBack) | the display content function for unsupport chart. |

#### Returns

`undefined` \| `boolean`

If no value is set, return the flag value, otherwise, return undefined;

___

### <a id="remove" name="remove"></a> remove

▸ **remove**(`name`): `void`

Removes a chart from the sheet by the indicate name.

**`example`**
```
var dataRange = "A1:D4";
activeSheet.charts.add('Chart1', GC.Spread.Sheets.Charts.ChartType.columnClustered, 250, 20, 600, 400, dataRange);
//button
$("#button1").click(function () {
     activeSheet.resumePaint();
     activeSheet.charts.remove("f2");
     activeSheet.repaint();
});
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the chart. |

#### Returns

`void`

___

### <a id="zindex" name="zindex"></a> zIndex

▸ **zIndex**(`name`, `zIndex?`): `any`

Gets or sets the z-index of chart.

**`example`**
```
var dataRange = "A1:D4";
activeSheet.charts.add('Chart1', GC.Spread.Sheets.Charts.ChartType.columnClustered, 250, 20, 600, 180, dataRange);
var dataRange2 = "A20:D24";
activeSheet.charts.add('Chart2', GC.Spread.Sheets.Charts.ChartType.columnClustered, 250, 180, 600, 180, dataRange2);
activeSheet.charts.zIndex('Chart1', 897);
activeSheet.charts.zIndex('Chart2', 890);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the chart. |
| `zIndex?` | `number` | The z-index of the chart. |

#### Returns

`any`

If the parameter 'zIndex' is null or undefined,it will return the z-index of the chart with the indicate name.
