Paramatrage de la zone Plot area d'un graphique
Chères amies, chers amis du forum
Grâce à l'enregistreur de macro j'ai pu déterminer les paramètre de ma zone plot area de mon graphe. Je les 'ai ensuite integrer dans ma sub mais rien à faire, j'ai toujours droit à une présentation aléatoire.
J'ai essayé de mettre mon bout de code à plusieurs endroit car je pense qu'Excel reconfigure automatiquement le graph, mais impossible de fixer mes parametre (il se trouve a l'intérieur d'une structure With ActiveChart)
voici le bout de code:
Code :
Sélectionner tout - Visualiser dans une fenêtre à part
.PlotArea.Height = 627
.PlotArea.Width = 505
.PlotArea.Left = 19
.PlotArea.Top = 36et voici le code pour mon graph:
Code :
Sélectionner tout - Visualiser dans une fenêtre à part
With ActiveChart
.HasTitle = True
.Axes(xlCategory).HasTitle = True
.Axes(xlValue).HasTitle = True
.PlotArea.Interior.ColorIndex = 2
.PlotArea.Border.LineStyle = xlNone
color = 51
'ici se trouve l'initialisation des .series.collection
.ChartTitle.Font.Name = "Arial Narrow"
.ChartTitle.Font.Size = 15
.ChartTitle.Font.Bold = True
.ChartTitle.Font.Italic = True
.ChartTitle.Left = .ChartArea.Left
.Axes(xlCategory).AxisTitle.Characters.Text = "Dates"
.Axes(xlCategory).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlCategory).AxisTitle.Font.Size = 10
.Axes(xlCategory).AxisTitle.Font.Bold = True
.Axes(xlCategory).AxisTitle.Font.Italic = True
.Axes(xlValue).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlValue).AxisTitle.Font.Size = 10
.Axes(xlValue).AxisTitle.Font.Bold = True
.Axes(xlValue).AxisTitle.Font.Italic = True
.Axes(xlValue).HasMajorGridlines = True
.Axes(xlCategory).HasMajorGridlines = True
.Axes(xlValue).MajorGridlines.Border.LineStyle = xlDot
.Axes(xlCategory).MajorGridlines.Border.LineStyle = xlDot
.Axes(xlValue).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlValue).TickLabels.Font.Size = 7
.Axes(xlCategory).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlCategory).TickLabels.Font.Size = 7
.Axes(xlCategory).TickLabels.NumberFormat = "d/m/yy;@"
.Axes(xlValue).MinimumScaleIsAuto = True
.Axes(xlValue).MaximumScaleIsAuto = True
.Axes(xlValue, xlPrimary).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlValue, xlPrimary).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlValue, xlPrimary).TickLabels.Font.Size = 7
.Axes(xlValue, xlPrimary).AxisTitle.Font.Size = 10
.Axes(xlValue, xlPrimary).AxisTitle.Font.Bold = True
.Axes(xlValue, xlPrimary).AxisTitle.Font.Italic = True
.Legend.Font.Name = "Arial Narrow"
.Legend.Font.Size = 5
.Legend.Border.LineStyle = xlNone
.Legend.Position = xlLegendPositionBottom
.PlotArea.Height = 627
.PlotArea.Width = 505
.PlotArea.Left = 19
.PlotArea.Top = 36
End WithY a til un moyen de fixer définitivement mes paramètre
Merci
NB: bizarrement pas à pas le code s'effectue correctement
Bonjour,
Serait-il possible d'avoir l'intégralité du code ?
Merci.
Lazade
Bien sur, j'ai mis une parti par peur d'illisibilité
Sub Graph(ByRef Tab_() As String, ByRef Date_1 As Date, ByRef Date_2 As Date, ByRef compteur_page As Byte)
ActiveSheet.ChartObjects.Delete
Dim RangeIndex, RangeDate, RangeData As Range
Dim i, j, k, l, color As Integer
Dim Cell As Range
Dim MonGraphe As Chart
Dim MesSeries As Series
Worksheets(compteur_page).Select
Set RangeIndex = Worksheets(compteur_page).Range(Cells(1, 2), Cells(1, 2).End(xlToRight))
Set RangeDate = Worksheets(compteur_page).Range(Cells(2, 1), Cells(2, 1).End(xlDown))
k = 0
Do
j = j + 1
k = k + 1
Loop While Date_1 <> Worksheets(compteur_page).Cells(k, 1).Value
k = 0
Do
i = i + 1
k = k + 1
Loop While Date_2 <> Worksheets(compteur_page).Cells(k, 1).Value
Set RangeData = Worksheets(compteur_page).Range(Cells(i, 1), Cells(j, 1))
ReDim Tab_Coord(UBound(Tab_))
k = 1
For l = 0 To UBound(Tab_)
For Each Cell In RangeIndex
k = k + 1
If Tab_(l) = Cell.Value Then
Set RangeData = Application.Union(RangeData, Range(Cells(i, k), Cells(j, k)))
End If
Next Cell
k = 1
Next l
RangeData.Select
Set MonGraphe = ThisWorkbook.Charts.Add
MonGraphe.ChartType = xlLineMarkers
MonGraphe.Location xlLocationAsObject, "Template"
With Worksheets("Template").ChartObjects(1)
.Left = Worksheets("Template").Cells(3, 8).Left
.Top = Worksheets("Template").Cells(3, 8).Top
.Height = 804
.Width = 539
End With
With ActiveChart
.HasTitle = True
.Axes(xlCategory).HasTitle = True
.Axes(xlValue).HasTitle = True
color = 51
l = 0
For Each MesSeries In .SeriesCollection
If Tab_(l) = "CAC 40" And compteur_page = 2 And l <> 0 Then
MesSeries.AxisGroup = 2
MesSeries.Border.ColorIndex = 3
MesSeries.Border.Weight = xlThick
MesSeries.MarkerStyle = xlMarkerStyleSquare
MesSeries.MarkerBackgroundColorIndex = 3
MesSeries.MarkerForegroundColorIndex = 3
MesSeries.MarkerSize = 2
MesSeries.Name = Tab_(l)
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "CAC 40"
.Axes(xlValue, xlSecondary).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlValue, xlSecondary).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlValue, xlSecondary).AxisTitle.Font.Bold = True
.Axes(xlValue, xlSecondary).AxisTitle.Font.Italic = True
.Axes(xlValue, xlSecondary).TickLabels.Font.Size = 7
.Axes(xlValue, xlSecondary).AxisTitle.Font.Size = 10
Else
color = color - 1
If Tab_(l) = "CAC 40" Then
MesSeries.Border.ColorIndex = 3
MesSeries.Border.Weight = xlThick
MesSeries.MarkerStyle = xlMarkerStyleSquare
MesSeries.MarkerBackgroundColorIndex = 3
MesSeries.MarkerForegroundColorIndex = 3
MesSeries.MarkerSize = 2
Else
MesSeries.Border.ColorIndex = color
MesSeries.Border.Weight = xlThick
MesSeries.MarkerStyle = xlMarkerStyleSquare
MesSeries.MarkerBackgroundColorIndex = color
MesSeries.MarkerForegroundColorIndex = color
MesSeries.MarkerSize = 2
End If
MesSeries.Name = Tab_(l)
End If
l = l + 1
Next MesSeries
Select Case compteur_page
Case Is = 2
.ChartTitle.Characters.Text = "Evolution des cours"
Case Is = 3
.ChartTitle.Characters.Text = "Evolution des rendements"
Case Is = 4
.ChartTitle.Characters.Text = "Evolution base 100"
End Select
.ChartTitle.Font.Name = "Arial Narrow"
.ChartTitle.Font.Bold = True
.ChartTitle.Font.Italic = True
.ChartTitle.Left = .ChartArea.Left
.Axes(xlCategory).AxisTitle.Characters.Text = "Dates"
.Axes(xlCategory).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlCategory).AxisTitle.Font.Bold = True
.Axes(xlCategory).AxisTitle.Font.Italic = True
Select Case compteur_page
Case Is = 2
.Axes(xlValue).AxisTitle.Characters.Text = "Cours"
Case Is = 3
.Axes(xlValue).AxisTitle.Characters.Text = "Rendements"
Case Is = 4
.Axes(xlValue).AxisTitle.Characters.Text = "Cours base 100"
End Select
.Axes(xlValue).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlValue).AxisTitle.Font.Bold = True
.Axes(xlValue).AxisTitle.Font.Italic = True
.Axes(xlValue).HasMajorGridlines = True
.Axes(xlCategory).HasMajorGridlines = True
.Axes(xlValue).MajorGridlines.Border.LineStyle = xlDot
.Axes(xlCategory).MajorGridlines.Border.LineStyle = xlDot
.Axes(xlValue).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlCategory).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlCategory).TickLabels.NumberFormat = "d/m/yy;@"
.Axes(xlValue).MinimumScaleIsAuto = True
.Axes(xlValue).MaximumScaleIsAuto = True
.Axes(xlValue, xlPrimary).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlValue, xlPrimary).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlValue, xlPrimary).AxisTitle.Font.Bold = True
.Axes(xlValue, xlPrimary).AxisTitle.Font.Italic = True
.Legend.Font.Name = "Arial Narrow"
.Legend.Border.LineStyle = xlNone
.Legend.Position = xlLegendPositionBottom
.PlotArea.Interior.ColorIndex = 2
.PlotArea.Border.LineStyle = xlNone
.Legend.Left = 54
.Legend.Top = 691
.ChartTitle.Font.Size = 15
.Axes(xlCategory).AxisTitle.Font.Size = 10
.Axes(xlCategory).TickLabels.Font.Size = 7
.Axes(xlValue, xlPrimary).TickLabels.Font.Size = 7
.Axes(xlValue, xlPrimary).AxisTitle.Font.Size = 10
.Legend.Font.Size = 5
.PlotArea.Left = 19
.PlotArea.Top = 36
.PlotArea.Height = 627
.PlotArea.Width = 505
End With
End SubBonjour,
Je n'ai pas assez d'éléments pour faire tourner la subroutine. Il me faudrait inventer un jeu de données.
Serait-il aussi possible d'avoir le classeur avec les données du graphe (ou une partie de ces données) ?
Merci.
le fichier est lourd, voici un liens ou tu peux le trouver
Merci
MonGraphe.Location xlLocationAsObject, "Template"
With Worksheets("Template").ChartObjects(1)
.Left = Worksheets("Template").Cells(3,8).Left
.Top = Worksheets("Template").Cells(3,8).Top
'.Height = 804
'.Width = 539
End With
Bonjour,
Je ne comprends pas bien l'expression "j'ai toujours droit à une présentation aléatoire".
S'agit-il d'un problème de taille de graphique ?
Est-ce que la suppression/mise en commentaire des 2 lignes ci-dessous de la partie de code ci dessus
'.Height = 804
'.Width = 539
donne le résultat attendu ?
Lazade
En fait quand je dis aléatoire c'est que j'ai jamais le graphe avec les paramtre que j'ai chois c'est a dire la hauteur et la largeur de la zone plotarea , la taille de police,....
Par contre pas a pas sa marche je comprend pas, c'est lorsque la macro se fait d'un coup que sa marche plus
Tu voulais dire "paramètres par défaut" ?
As-tu fais l'essai que je t'ai indiqué ? Chez moi cela fait une grande différence.
A+
Merci pour ton aide
J'ai trouver le probleme, en fait à un moment je suppose l'endroit du code que tu m'as signalé, le graph devient trop grand, alors Excel corrige avec des valeurs aléatoire le reste des parametre, voici le code qui fonctionne bien:
Set MonGraphe = ThisWorkbook.Charts.Add
MonGraphe.ChartType = xlLineMarkers
MonGraphe.Location xlLocationAsObject, "Template"
With Worksheets("Template").ChartObjects(1)
.Left = Worksheets("Template").Cells(3, 8).Left
.Top = Worksheets("Template").Cells(3, 8).Top
.Height = 804
.Width = 539
End With
With ActiveChart
.HasTitle = True
.Axes(xlCategory).HasTitle = True
.Axes(xlValue).HasTitle = True
Select Case compteur_page
Case Is = 2
.ChartTitle.Characters.Text = "Evolution des cours"
Case Is = 3
.ChartTitle.Characters.Text = "Evolution des rendements"
Case Is = 4
.ChartTitle.Characters.Text = "Evolution base 100"
End Select
.ChartTitle.Font.Name = "Arial Narrow"
.ChartTitle.Font.Bold = True
.ChartTitle.Font.Italic = True
.ChartTitle.Left = .ChartArea.Left
.ChartTitle.Font.Size = 15
.Axes(xlCategory).AxisTitle.Characters.Text = "Dates"
.Axes(xlCategory).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlCategory).AxisTitle.Font.Bold = True
.Axes(xlCategory).AxisTitle.Font.Italic = True
Select Case compteur_page
Case Is = 2
.Axes(xlValue).AxisTitle.Characters.Text = "Cours"
Case Is = 3
.Axes(xlValue).AxisTitle.Characters.Text = "Rendements"
Case Is = 4
.Axes(xlValue).AxisTitle.Characters.Text = "Cours base 100"
End Select
.Axes(xlValue).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlValue).AxisTitle.Font.Bold = True
.Axes(xlValue).AxisTitle.Font.Italic = True
.Axes(xlValue).HasMajorGridlines = True
.Axes(xlCategory).HasMajorGridlines = True
.Axes(xlValue).MajorGridlines.Border.LineStyle = xlDot
.Axes(xlCategory).MajorGridlines.Border.LineStyle = xlDot
.Axes(xlValue).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlCategory).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlCategory).TickLabels.NumberFormat = "d/m/yy;@"
If compteur_page = 3 Then
.Axes(xlCategory).TickLabelPosition = xlLow
End If
.Axes(xlValue).MinimumScaleIsAuto = True
.Axes(xlValue).MaximumScaleIsAuto = True
.Axes(xlValue, xlPrimary).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlValue, xlPrimary).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlValue, xlPrimary).AxisTitle.Font.Bold = True
.Axes(xlValue, xlPrimary).AxisTitle.Font.Italic = True
.Legend.Font.Name = "Arial Narrow"
.Legend.Border.LineStyle = xlNone
.Legend.Position = xlLegendPositionBottom
.PlotArea.Interior.ColorIndex = 2
.PlotArea.Border.LineStyle = xlNone
.Legend.Left = 54
.Legend.Top = 691
.Legend.Position = xlLegendPositionBottom
.Legend.Font.Size = 5
.Axes(xlCategory).AxisTitle.Font.Size = 10
.Axes(xlCategory).TickLabels.Font.Size = 7
.Axes(xlValue).TickLabels.Font.Size = 7
.Axes(xlValue).AxisTitle.Font.Size = 10
.PlotArea.Left = 25
.PlotArea.Top = 50
.PlotArea.Height = 150
.PlotArea.Width = 550
color = 51
l = 0
For Each MesSeries In .SeriesCollection
If Tab_(l) = "CAC 40" And compteur_page = 2 And l <> 0 Then
MesSeries.AxisGroup = 2
MesSeries.Border.ColorIndex = 3
MesSeries.Border.Weight = xlThick
MesSeries.MarkerStyle = xlMarkerStyleSquare
MesSeries.MarkerBackgroundColorIndex = 3
MesSeries.MarkerForegroundColorIndex = 3
MesSeries.MarkerSize = 2
MesSeries.Name = Tab_(l)
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "CAC 40"
.Axes(xlValue, xlSecondary).AxisTitle.Font.Name = "Arial Narrow"
.Axes(xlValue, xlSecondary).TickLabels.Font.Name = "Arial Narrow"
.Axes(xlValue, xlSecondary).AxisTitle.Font.Bold = True
.Axes(xlValue, xlSecondary).AxisTitle.Font.Italic = True
.Axes(xlValue, xlSecondary).TickLabels.Font.Size = 7
.Axes(xlValue, xlSecondary).AxisTitle.Font.Size = 10
Else
color = color - 1
If Tab_(l) = "CAC 40" Then
MesSeries.Border.ColorIndex = 3
MesSeries.Border.Weight = xlThick
MesSeries.MarkerStyle = xlMarkerStyleSquare
MesSeries.MarkerBackgroundColorIndex = 3
MesSeries.MarkerForegroundColorIndex = 3
MesSeries.MarkerSize = 2
Else
MesSeries.Border.ColorIndex = color
MesSeries.Border.Weight = xlThick
MesSeries.MarkerStyle = xlMarkerStyleSquare
MesSeries.MarkerBackgroundColorIndex = color
MesSeries.MarkerForegroundColorIndex = color
MesSeries.MarkerSize = 2
End If
MesSeries.Name = Tab_(l)
End If
l = l + 1
Next MesSeries
End With