1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| '1) On choisit les données
Sheets("Feuil2").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatter 'Type du graphique: ici nuage de points
ActiveChart.SeriesCollection.NewSeries
'ActiveChart.SetSourceData Source:=Sheets("dataBase").Range("A1:A" & i & "," & lettre2 & "1 :" & lettre2 & i)
ActiveChart.SeriesCollection(1).XValues = "=dataBase!$A$2:$A$" & i
ActiveChart.SeriesCollection(1).Values = "=dataBase!$" & lettre2 & "$2:$" & lettre2 & "$" & i
'2) on rajoute un cadre autour de la légende
ActiveChart.Legend.Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
End With
'3) On insère un titre sur le graphique
ActiveChart.ChartArea.Select
ActiveChart.SetElement (msoElementChartTitleAboveChart)
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Nombre de défauts sur 100m en fonction du temps"
With Selection.Format.TextFrame2.TextRange.Characters(1, 47).ParagraphFormat 'Format du titre
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 47).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
'4) On ajoute un titre à l'axe des abscisses:
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
Selection.Format.TextFrame2.TextRange.Characters.Text = "Temps"
With Selection.Format.TextFrame2.TextRange.Characters(1, 5).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 5).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
'5) on ajoute un titre à l'axe des ordonnées
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleRotated)
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Valeurs"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Valeurs"
With Selection.Format.TextFrame2.TextRange.Characters(1, 7).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 7).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
Cells(1, 1).Select
End Sub |
Partager