Bonjour ,
je souhaite effectuer un histogramme empilé et afficher deux courbes dans une macro VBA.
J'ai testé le code en effectuant un histogramme empilé + 1 courbe et ça fonctionne. Mais lorsque je refais le même code avec deux courbes ça ne fonctionne pas , aucune courbe ne s'affiche sur l'histogramme .
Pourriez vous me trouver l'erreur?
Mes données sont en pièce jointe et voici la macro :
Public Sub CreationGraphe1()
Dim MonGraphe As Chart, MaPlage As Range
Set MaPlage = ActiveSheet.Range(Cells(4, 1), Cells(13, 9))
Set MonGraphe = ThisWorkbook.Charts.Add
MonGraphe.ChartType = xlColumnStacked100
MonGraphe.SetSourceData MaPlage, xlColumns
'A ce point j'ai crée un graphe de base contenant toutes les séries. Je vais maintenant modifier les series rollers et velo
'afin de pouvoir la mettre en nuage de points et l'affecter à l'axe secondaire des ordonnées.
With MonGraphe.SeriesCollection(7)
.ChartType = xlLine
.AxisGroup = 2
With .Border
.Weight = xlMedium
.LineStyle = xlContinuous
.ColorIndex = 5
End With
End With
With MonGraphe.SeriesCollection(8)
.ChartType = xlLine
.AxisGroup = 2
With .Border
.Weight = xlMedium
.LineStyle = xlContinuous
.ColorIndex = 10
End With
End With
' on met les ecarts entre les histogrammes a 0
MonGraphe.SeriesCollection(5).Select
With MonGraphe.ChartGroups(1)
.Overlap = 100
.GapWidth = 0
.HasSeriesLines = False
End With
'change de couleur au barres
With MonGraphe.SeriesCollection(1)
.Interior.ColorIndex = 37
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(2)
.Interior.ColorIndex = 44
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(3)
.Interior.ColorIndex = 45
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(4)
.Interior.ColorIndex = 46
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(5)
.Interior.ColorIndex = 35
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(6)
.Interior.ColorIndex = 36
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
'Mis en forme de la légende
MonGraphe.Legend.Select
Selection.Position = xlBottom
Selection.Width = 600
Selection.Left = 74
Selection.Top = 376
'Je vais maintenant mettre les libellés des axes et du titre
With MonGraphe
.HasTitle = True
With .ChartTitle
.Characters.Text = "Fréquences cardiaques"
.Shadow = True
.Border.Weight = xlHairline
End With
With .Axes(xlValue, xlPrimary)
.MinimumScale = 40
.MaximumScale = 100
.HasTitle = True
.AxisTitle.Characters.Text = "% FC"
End With
With .Axes(xlValue, xlSecondary)
.MinimumScale = 80
.MaximumScale = 202
.HasTitle = True
.AxisTitle.Characters.Text = "FC moy"
End With
End With
End Sub
je souhaite effectuer un histogramme empilé et afficher deux courbes dans une macro VBA.
J'ai testé le code en effectuant un histogramme empilé + 1 courbe et ça fonctionne. Mais lorsque je refais le même code avec deux courbes ça ne fonctionne pas , aucune courbe ne s'affiche sur l'histogramme .
Pourriez vous me trouver l'erreur?
Mes données sont en pièce jointe et voici la macro :
Public Sub CreationGraphe1()
Dim MonGraphe As Chart, MaPlage As Range
Set MaPlage = ActiveSheet.Range(Cells(4, 1), Cells(13, 9))
Set MonGraphe = ThisWorkbook.Charts.Add
MonGraphe.ChartType = xlColumnStacked100
MonGraphe.SetSourceData MaPlage, xlColumns
'A ce point j'ai crée un graphe de base contenant toutes les séries. Je vais maintenant modifier les series rollers et velo
'afin de pouvoir la mettre en nuage de points et l'affecter à l'axe secondaire des ordonnées.
With MonGraphe.SeriesCollection(7)
.ChartType = xlLine
.AxisGroup = 2
With .Border
.Weight = xlMedium
.LineStyle = xlContinuous
.ColorIndex = 5
End With
End With
With MonGraphe.SeriesCollection(8)
.ChartType = xlLine
.AxisGroup = 2
With .Border
.Weight = xlMedium
.LineStyle = xlContinuous
.ColorIndex = 10
End With
End With
' on met les ecarts entre les histogrammes a 0
MonGraphe.SeriesCollection(5).Select
With MonGraphe.ChartGroups(1)
.Overlap = 100
.GapWidth = 0
.HasSeriesLines = False
End With
'change de couleur au barres
With MonGraphe.SeriesCollection(1)
.Interior.ColorIndex = 37
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(2)
.Interior.ColorIndex = 44
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(3)
.Interior.ColorIndex = 45
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(4)
.Interior.ColorIndex = 46
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(5)
.Interior.ColorIndex = 35
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
With MonGraphe.SeriesCollection(6)
.Interior.ColorIndex = 36
With .Border
.Weight = xlThin
.LineStyle = xlNone
End With
End With
'Mis en forme de la légende
MonGraphe.Legend.Select
Selection.Position = xlBottom
Selection.Width = 600
Selection.Left = 74
Selection.Top = 376
'Je vais maintenant mettre les libellés des axes et du titre
With MonGraphe
.HasTitle = True
With .ChartTitle
.Characters.Text = "Fréquences cardiaques"
.Shadow = True
.Border.Weight = xlHairline
End With
With .Axes(xlValue, xlPrimary)
.MinimumScale = 40
.MaximumScale = 100
.HasTitle = True
.AxisTitle.Characters.Text = "% FC"
End With
With .Axes(xlValue, xlSecondary)
.MinimumScale = 80
.MaximumScale = 202
.HasTitle = True
.AxisTitle.Characters.Text = "FC moy"
End With
End With
End Sub