Blog de Augusto Simoes (MVP)

Sharepoint, OCS, Windows Server ...

Augusto Simoes

Consultant Infrastructure & Trainer

Ma mission est de concevoir les architectures de messageries unifiés et collaboratives afin d'accompagner nos clients vers ces nouvelles technologies.

  • Microsoft Certified Trainer
  • Microsoft Certified Systems Engineer
  • Microsoft Certified Technology Specialist :SharePoint, WSS, OCS 2007, Vista, Windows 2008
  • Microsoft Certified Database Administrator SQL 2000, 2005


MVP Logo


MyTag

Mon Profile Chez Microsoft



 

 

RecentComments

Comment RSS

[PowerShell] Integration de Microsoft Chart Controls for Microsoft .Net 3.5

Comment faire de beau graphique dans PowerShell simplement! Microsoft offre un kit qui fournit des controles pour pouvoir créer des graphiques dynamiques dans vos projets Visual Studio… Alors pourquoi ne pas les utiliser avec PowerShell.

Installer les Microsoft Chart Control for .Net 3.5

Une fois installer, déclarez les librairies de Microsoft Chart Control et lancez-vous dans le code!

#############################################################################################
#                  NECESSITE L'INSTALLATION DE MICROSOFT CHART CONTROL                                              
#                              FOR MICROSOFT .NET 3.5                                     

# http://www.microsoft.com/downloads/details.aspx?FamilyId=130F7986-BF49-4FE5-9CA8-910AE6EA442C&displaylang=en                                                                                                                                   
#                                                                                         

#############################################################################################

#############################################################################################
#                   Chargement des Assembly                                                 #
#-------------------------------------------------------------------------------------------#
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")                    #
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")  #
#############################################################################################

#############################################################################################
#                        Création de l'objet Graphique                                      #
#-------------------------------------------------------------------------------------------#
$MyChart = New-object System.Windows.Forms.DataVisualization.Charting.Chart                 #
$MyChart.Width = 500                                                                        #
$MyChart.Height = 500                                                                       #
$MyChart.Left = 40                                                                          #
$MyChart.Top = 30                                                                           #
#############################################################################################

#############################################################################################
#               Creation de la zone du graphique dans le graphique                          #
#-------------------------------------------------------------------------------------------#
$GraphZone = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea           #
$GraphZone.Area3DStyle.Enable3D="True"                                                      #
$MyChart.ChartAreas.Add($GraphZone)                                                         #
#############################################################################################

##################################################################################################
#                   Récupération des données du graphique                                        #
#                                                                                                #
#                    La taille des sous-dossiers                                                 #
#------------------------------------------------------------------------------------------------#
$MyFolders = Get-ChildItem -Path C:\Powershell|Where-Object{$_.psIsContainer -eq $True}          #
$Size = @{}                                                                                      #                                                                        
foreach($folder in $MyFolders)                                                                   #
{                                                                                                #
$colItems = (Get-ChildItem -Path $folder.FullName -Recurse|Measure-Object -property length -sum) #
$Mykeys = $folder.Name                                                                           #
$MyKeys += "\n" +$folder.CreationTime                                                            #
$MyValue += " (" +"{0:N2}" -f ($colItems.sum/1Mb)+' Mb)'                                         #
$Size += @{$MyKeys="{0:N3}" -f ($colItems.sum/1Mb)}                                              #
                                                                                                 #
}                                                                                                #
##################################################################################################

##################################################################################################
#                 Ajout des données du graphique                                                 #
#------------------------------------------------------------------------------------------------#
[void]$MyChart.Series.Add("Data")
$MyChart.Series["Data"].Points.DataBindXY($Size.Keys, $Size.Values)

##################################################################################################
#                Ajout Titre et Labels
#-------------------------------------------------------------------------------------------------
[void]$MyChart.Titles.Add("Size of folders")
$GraphZone.AxisX.Title = "Folder"
$GraphZone.AxisY.Title = "Size of Folder (Mb)"

##################################################################################################
#              Changement de la couleur de la zone de texte                                      #
#-------------------------------------------------------------------------------------------------
$MyChart.BackColor = [System.Drawing.Color]::White
# Valeur possible pour BackColor: Une couleur au choix
#
$MyChart.Palette = [System.Windows.Forms.DataVisualization.Charting.ChartColorPalette]::EarthTones
#
# Valeur possible pour Palette:
# None,Bright,Grayscale,Excel,Light,Pastel,EarthTones,SemiTransparent,Berry,Chocolate
# Fire, SeaGreen, BrightPastel
#
##################################################################################################
#              le data Chart                                          
#-------------------------------------------------------------------------------------------------
$MyChart.Series["Data"]["DrawingStyle"] = "Cylinder"
$MyChart.Series["Data"].Sort([System.Windows.Forms.DataVisualization.Charting.PointSortOrder]::Ascending, "Y")
$MyChart.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Bar

#Options de SeriesChartType
# Point, FastPoint, Bubble, Line, Spline, StepLine, FastLine, Bar, StackedBar, StackedBar100, Column,
# StackedColumn, StackedColumn100,Area, SplineArea, StackedArea, StackedArea100, Pie, Doughnut, Stock,
# Candlestick, Range, SplineRange, RangeBar, RangeColumn, Radar,Polar, ErrorBar, BoxPlot, Renko,
# ThreeLineBreak, Kagi, PointAndFigure, Funnel, Pyramid
##################################################################################################

##################################################################################################
#                            Affiche le graphique dans la Windows Form                           #
#------------------------------------------------------------------------------------------------#
$MyChart.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right

-bor [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left
$Form = New-Object Windows.Forms.Form
$Form.Text = "Graphique PowerShell - Microsoft Chart Control"
$Form.Width = 600
$Form.Height = 600
$Form.controls.add($MyChart)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()
#################################################################################################

Le résultat en image….

MicrosoftChartControl


Bookmark and Share
Posted: Sep 08 2009, 07:05 by collaboration | Comments (4) RSS comment feed |
  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: PowerShell | Dotnet-France

Comments

arnold said:

bonjour monsieur,
je suis tres heureux de trouver votre experience pour
le chart controle.
svp, je besoin une petit assistence de votre part.
j'ai confectionner un pre modelle avec excel
et ajouter le module dans le scripte du PoSh. je utilisrais que les variable(import xml)
merci.

# January 07 2010, 11:45

Simbozel said:

Bonjour,
je reçois un une erreur à l'éxecution :
Measure-Object : Property "length" cannot be found in any object(s) input.
At C:\PowerSQL\GRAPHIQUE\Graphique_20100211.ps1:45 char:74
+ $colItems = (Get-ChildItem -Path $folder.FullName -Recurse|Measure-Object <<<<  -property length -sum) #
    + CategoryInfo          : InvalidArgument: (Smile [Measure-Object], PSArgumentException
    + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand
The term '-bor' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
At C:\PowerSQL\GRAPHIQUE\Graphique_20100211.ps1:98 char:5
+ -bor <<<<  [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left
    + CategoryInfo          : ObjectNotFound: (-bor:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Cancel

merci de votre retour.

# February 11 2010, 10:43

Augusto said:

Pas la bonne version de Powershell ?

# February 13 2010, 08:45

Augusto said:

Le script est:
$MyChart.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor
[System.Windows.Forms.AnchorStyles]::Top -bor

# February 13 2010, 08:49

Add comment




biuquote
  • Comment
  • Preview
Loading

captcha

*