J'ai trouvé, tu cherches à ajouter ton type de chart à ta series "data", alors que tu ne l'as pas encore créé.
Place
$G_Graphique.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie
apres
1 2 3
| # Ajouter des données au graphique
$V_Data = @{Test=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539; Paris=2188500}
[void]$G_Graphique.Series.Add("Data") |
Et ca fonctionne.
Le code complet fonctionnel :
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
|
#****************************************************************************************************************
#*** Chargement des bibliothèques Winforms
#*** Chargement de la bibliothèque pour avoir accès aux outils graphiques (partie de .NET)
#****************************************************************************************************************
[void][Reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.assembly]::LoadWithPartialName("System.Drawings")
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")
# Forme principale
$Graphique = New-Object System.Windows.Forms.Form
$Graphique.Text = "Test"
$Graphique.SizeGripStyle = "Hide"
$Graphique.Opacity = 1.0 #1.0 = 100 %; 0.0 = invisible
$Graphique.Location.X = 10
$Graphique.Location.Y = 22
$Graphique.Width = 700
$Graphique.Height = 700
$Graphique.Icon = $C_MailOpenClose
$Graphique.Maximizebox = $False # Bouton pour mettre en plein écran
$Graphique.Minimizebox = $True # Bouton pour mettre dans la barre des tâches
# Objet Graphique (G_)
$G_Graphique = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$Graphique.controls.add($G_Graphique) #
$Graphique.Add_Shown({$Graphique.Activate()}) # Afficher le graphique dans la forme
$G_Graphique.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left
# Objet Zone Graphique (ZG_)
$ZG_GraphArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
# Paramètres du graphique
$G_Graphique.ChartAreas.Add($ZG_GraphArea) # Ajout du graphique dans la zone graphique
[void]$G_Graphique.Titles.Add("Top 5 European Cities by Population")
$G_Graphique.BackColor = [System.Drawing.Color]::Transparent # Enleve la zone blanche derrière le graphique
# Ajouter des données au graphique
$V_Data = @{Test=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539; Paris=2188500}
[void]$G_Graphique.Series.Add("Data")
$G_Graphique.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie
$G_Graphique.Series["Data"].Points.DataBindXY($V_Data.Keys, $V_Data.Values)
#****************************************************************************************************************
#*** Affichage
#****************************************************************************************************************
$Graphique.ShowDialog() |
Cordialement.
DeWaRs
Partager