Il est assez facile de colorer une ligne de graphique en VBA. Voici quelques notes.
Dim cht As Chart
Dim sc As Series
Dim blnBad As Boolean
Dim j
j = 85 'RGB orange '
blnBad = False
'This is a chart called Chart 1, it would be possible '
'to use the charts collection '
Set cht = ActiveSheet.ChartObjects("Chart 1").Chart
'A chart is composed of series of data ... '
For Each sc In cht.SeriesCollection
' ... that you can iterate through to pick up '
' the individual data values, or a data range. '
' Values in this case. '
For i = LBound(sc.Values) To UBound(sc.Values)
' That can be checked against another set of '
' values in the range Bad. '
With ActiveSheet.Range("Bad")
' So, look for the value ... '
Set c = .Find(sc.Values(i), lookat:=xlWhole, LookIn:=xlValues)
' and if it is found ... '
If Not c Is Nothing Then
' ... then set the Bad flag '
blnBad = True
End If
End With
Next
' So, this range contains a Bad value '
' and we will colour it red ... '
If blnBad Then
sc.Border.Color = RGB(255, 0, 0)
' ... not forgetting the markers '
sc.MarkerForegroundColor = RGB(255, 0, 0)
Else
' Otherwise, use an increasingly yellow colour '
sc.Border.Color = RGB(255, j, 0)
sc.MarkerForegroundColor = RGB(255, j, 0)
j = j + 30 ' getting more yellow
' Debug.Print j ' uncomment to see j in the immediate window '
End If
blnBad = False
Next
End Sub
Merci, pourriez-vous donner une très brève description de ce que cela fait? Que devrait-on faire dans la gamme 'Bad'? – geometrikal
La plage Bad de l'exemple contenait une liste de valeurs pouvant être mises en correspondance avec chaque valeur de la série. Votre configuration est probablement différente, mais je n'ai pas suffisamment d'informations. – Fionnuala
Merci pour la description. La configuration que je vise est légèrement différente - je veux tracer une seule gamme, appelons-la 'rangeValues' mais je veux que la couleur de la ligne change avec la valeur dans une autre gamme 'rangeError'. En substance, une ligne de série multicolore. :) – geometrikal