Option Explicit
Option Base 1
Dim Cht As ChChart
Dim C
Private Sub Btn_Ok_Click()
Dim i As Integer
Dim x As Integer
Dim Tableau(14), Plage(14)
Sheets("Analyse").Select
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotCache.Refresh
Set C = ChartSpace1.Constants
Set Cht = ChartSpace1.Charts.Add
' Supprimer les séries existantes dans le graphique
'For i = Cht.SeriesCollection.Count To 1 Step -1
' Cht.SeriesCollection.Delete i - 1
'Next i
'Définit les abscisses
With Sheets("Analyse")
For i = 1 To 14
Tableau(i) = Cells(i + 4, 4)
Next i
End With
'Définit les propriétés du graphique
With Cht
' .HasLegend = True
' .Legend.Position = chLegendPositionBottom
.HasTitle = True
.Title.Caption = "Contrôle poids " & Cbx_Element.Value & " P" & _Cbx_Programme.Value & " Atelier" & Cbx_Atelier.Value
.Type = C.chChartTypeSmoothLineMarkers
.Axes(1).HasTitle = True
.Axes(1).Title.Caption = "Poids (g)"
.Axes(0).HasTitle = True
.Axes(0).Title.Caption = "Semaines "
End With
Cht.SeriesCollection.Add
'Définit les ordonnées
With Sheets("Analyse")
For i = 1 To 14
Plage(i) = Cells(i + 4, 5)
Next i
End With
'Remplit le graphique avec les valeurs définies précédemment
With Cht
.SetData C.chDimCategories, C.chDataLiteral, Tableau
.SeriesCollection(0).DataLabelsCollection.Add
.SeriesCollection(0).DataLabelsCollection(0).Position = chLabelPositionCenter
.SeriesCollection(0).DataLabelsCollection(0).Font.Color = "black"
.SeriesCollection(0).SetData C.chDimValues, C.chDataLiteral, Plage
End With
Erase Plage
End Sub