VBA histogramme + courbe

MathildeQ

XLDnaute Nouveau
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
 

Pièces jointes

  • donnees.xls
    14 KB · Affichages: 188
  • donnees.xls
    14 KB · Affichages: 213
  • donnees.xls
    14 KB · Affichages: 195

Catrice

XLDnaute Barbatruc
Re : VBA histogramme + courbe

Bonsoir,

en forçant les "Marker" ça a l'air de fonctionner.
Par defaut, ils sont créés sans couleur de premier plan et d'arriere plan.

With MonGraphe.SeriesCollection(7)
.ChartType = xlLine
.AxisGroup = 2
With .Border
.Weight = xlMedium
.LineStyle = xlContinuous
.ColorIndex = 5
End With
.MarkerBackgroundColorIndex = 4
.MarkerForegroundColorIndex = 4
.MarkerStyle = xlSquare
.MarkerSize = 5

End With

With MonGraphe.SeriesCollection(8)
.ChartType = xlLine
.AxisGroup = 2
With .Border
.Weight = xlMedium
.LineStyle = xlContinuous
.ColorIndex = 10
End With
.MarkerBackgroundColorIndex = 6
.MarkerForegroundColorIndex = 6
.MarkerStyle = xlSquare
.MarkerSize = 5

End With
 
Dernière édition:

MathildeQ

XLDnaute Nouveau
Re : VBA histogramme + courbe

Je te remercie , je vois bien les "markers" maintenant mais toujours pas les courbes.
Il ne m'affiche pas la ligne.
Pourtant je met bien : .ChartType = xlLine

et la couleur , je comprend pas car avec juste une seule courbe cela fonctionne.
j'obtiens bien la courbe superposée à l'histogramme empilé.
C'est peut être une histoire de backgound?
 

Catrice

XLDnaute Barbatruc
Re : VBA histogramme + courbe

Re,

Pour la courbe, tu mets =NA() dans les cellules vides.

Pour la couleur, je crois que ça vient du fait que tu passes d'abord par des histogrammes.
Dans les Histogrammes, il n'y a pas de propriété Marker => d'où au passage en courbe, la propriété est vide. Il faut la "forcer".

Quand tu fais une courbe seule, il y a un marker par defaut ;)
 
Dernière édition:

Marie1982

XLDnaute Nouveau
Re : VBA histogramme + courbe

Bonjour,

Dans le même ordre d'idée, comment faire pour enlever les markers sur une courbe???

Je spécifie charttype xlLine et j'ai quand même des markers....

Ma courbe a environ 1500 points alors avec des markers ce n'est pas très joli..

Merci!
 

Statistiques des forums

Discussions
312 450
Messages
2 088 515
Membres
103 873
dernier inscrit
Sabin