2D Chart for WinForms | ComponentOne
Charting Data / Defining the Chart Data Objects / Defining the ChartGroup Object
In This Topic
    Defining the ChartGroup Object
    In This Topic

    Data in a chart is organized into ChartGroups. 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, a chart group is represented by a ChartGroup object. The ChartGroup objects are organized into the ChartGroupsCollection, 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:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    C1Chart1.ChartGroups.ChartGroupsCollection(0).ChartType = Chart2DTypeEnum.XYPlot
    

    To write code in C#

    C#
    Copy Code
    c1Chart1.ChartGroups.ChartGroupsCollection[0].ChartType = Chart2DTypeEnum.XYPlot;
    

    Secondly, the Group0 and Group1 properties of the ChartGroup's object return the associated ChartGroup and allow circumvention of the long collection name by using the following code:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    C1Chart1.ChartGroups.Group1.ChartType = Chart2DTypeEnum.XYPlot
    

    To write code in C#

    C#
    Copy Code
    c1Chart1.ChartGroups.Group1.ChartType = Chart2DTypeEnum.XYPlot;
    

    The ChartGroupsCollection accepts usual iteration methods as illustrated below:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim cg As ChartGroup
    For Each cg In C1Chart1.ChartGroups.ChartGroupsCollection
            cg.ChartType = Chart2DTypeEnum.XYPlot
    Next
    

    To write code in C#

    C#
    Copy Code
    ChartGroup cg;
    foreach ( cg In c1Chart1.ChartGroups.ChartGroupsCollection )
            cg.ChartType = Chart2DTypeEnum.XYPlot;
    
    See Also