# Defining the ChartGroup Object

## Content



Data in a chart is organized into [ChartGroups](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroups.html). Each chart contains two ChartGroups (although most charts will only use the first ChartGroup), each of which is treated as a separate entity. ChartGroups allow more than one chart to be displayed in the ChartArea and provide access to many of the chart-specific properties.

In [C1Chart](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.C1Chart.html), a chart group is represented by a [ChartGroup](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroup.html) object. The ChartGroup objects are organized into the [ChartGroupsCollection](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroupsCollection.html), which is accessed through the ChartGroups object. This collection provides access to the ChartGroups through two methods.

First the individual chart groups can be accessed through the collection. For example, the following code shows how to access individual chart groups through the ChartGroupsCollection object:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
C1Chart1.ChartGroups.ChartGroupsCollection(0).ChartType = Chart2DTypeEnum.XYPlot
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
c1Chart1.ChartGroups.ChartGroupsCollection[0].ChartType = Chart2DTypeEnum.XYPlot;
```

DOC-DETAILS-TAG-CLOSE

Secondly, the [Group0](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroups.Group0.html) and [Group1](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroups.Group1.html) properties of the ChartGroup's object return the associated ChartGroup and allow circumvention of the long collection name by using the following code:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
C1Chart1.ChartGroups.Group1.ChartType = Chart2DTypeEnum.XYPlot
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
c1Chart1.ChartGroups.Group1.ChartType = Chart2DTypeEnum.XYPlot;
```

DOC-DETAILS-TAG-CLOSE

The ChartGroupsCollection accepts usual iteration methods as illustrated below:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
Dim cg As ChartGroup
For Each cg In C1Chart1.ChartGroups.ChartGroupsCollection
        cg.ChartType = Chart2DTypeEnum.XYPlot
Next
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
ChartGroup cg;
foreach ( cg In c1Chart1.ChartGroups.ChartGroupsCollection )
        cg.ChartType = Chart2DTypeEnum.XYPlot;
```

DOC-DETAILS-TAG-CLOSE

## See Also

[Defining the ChartData Object](/componentone/docs/win/online-chart2d/chartingdata/definingthechartdata/definingthechartdata1)