Share via


Chart.ChartObjects, méthode

Obtient un objet qui représente un seul graphique incorporé (objet ChartObject) ou une collection de tous les graphiques incorporés (objet ChartObjects) dans la feuille.

Espace de noms :  Microsoft.Office.Tools.Excel
Assembly :  Microsoft.Office.Tools.Excel (dans Microsoft.Office.Tools.Excel.dll)

Syntaxe

'Déclaration
Function ChartObjects ( _
    Index As Object _
) As Object
Object ChartObjects(
    Object Index
)

Paramètres

  • Index
    Type : System.Object
    Nom ou numéro du graphique.Cet argument peut être un tableau, pour spécifier plusieurs graphiques.

Valeur de retour

Type : System.Object
Objet qui représente soit un graphique incorporé seul (un objet ChartObject), soit une collection de tous les graphiques incorporés (une collection ChartObjects) sur la feuille.

Notes

Cette méthode n'est pas équivalente à la propriété Charts. Cette méthode retourne des graphiques incorporés ; la propriété Charts retourne des feuilles de graphique. Utilisez la propriété Chart pour retourner l'objet Chart pour un graphique incorporé.

Paramètres optionnels

Pour plus d'informations sur les paramètres optionnels, consultez Paramètres optionnels dans les solutions Office.

Exemples

L'exemple de code suivant crée un Chart, puis utilise la méthode ChartObjects pour afficher si le graphique a été créé ou non par Microsoft Office Excel.

Private Sub UseChartObjects()
    Me.Range("A1", "A5").Value2 = 22
    Me.Range("B1", "B5").Value2 = 55

    Dim Chart1 As Microsoft.Office.Tools.Excel.Chart = _
        Me.Controls.AddChart(Me.Range("D2", "H12"), "Chart1")

    Chart1.SetSourceData(Me.Range("A1", "B5"), Excel.XlRowCol.xlColumns)
    Chart1.ChartType = Excel.XlChartType.xlColumnClustered

    Dim chartObjects1 As Excel.ChartObjects = _
        CType(Chart1.ChartObjects(), Excel.ChartObjects)

    If chartObjects1.Creator = Excel.XlCreator.xlCreatorCode Then
        MsgBox("The ChartObjects was created by Microsoft Office Excel.")
    End If

End Sub
private void UseChartObjects()
{
    this.Range["A1", "A5"].Value2 = 22;
    this.Range["B1", "B5"].Value2 = 55;

    Microsoft.Office.Tools.Excel.Chart chart1 =
        this.Controls.AddChart(this.Range["D2", "H12"], 
        "chart1");

    chart1.SetSourceData(this.Range["A1", "B5"], 
        Excel.XlRowCol.xlColumns);
    chart1.ChartType = Excel.XlChartType.xlColumnClustered;

    Excel.ChartObjects chartObjects1 =
        (Excel.ChartObjects)chart1.ChartObjects();

    if (chartObjects1.Creator == Excel.XlCreator.xlCreatorCode)
    {
        MessageBox.Show("The ChartObjects was created by " +
            "Microsoft Office Excel.");
    }
}

Sécurité .NET Framework

Voir aussi

Référence

Chart Interface

Microsoft.Office.Tools.Excel, espace de noms