Charts with PowerShell advance techniques
Charts with PowerShell advance techniques is all about visualizing your output data in the form of charts. If you are going to show disk space info, nothing more than a nice chart will worth looking at. If you are sending a report to your management, nothing will take their attention more than charts. I love getting charts as a high level output, with more tables and data for extra details.
PowerShell charts are easy to produce if you know how. I had a previous blog post introducing PowerShell charts in great details. I recommend you look at that post before moving forward. What is new in this blog post is to extend the capabilities in the previous PowerShell charts script with new input data type [hash table] and new theme options.
Script Requirements
The machine that run the charts with PowerShell advance script should have:
- .NET 3.5
- Microsoft Chart Controls for Microsoft .NET Framework 3.5.
What is different this time?
Compared to my previous PowerShell charts script, this charts with PowerShell advance script adds the following two features:
- The previous script only accepts array of objects as an input data, and requires Obj_Key and Obj_Value parameters to identify X-axis and Y-axis. Now, with this new version of the script, you can have a hash table as an input as well.
- This new script contain a -Theme. This parameter can take a number from 1 to 7 as a theme choice, and the script will do predefined customization for you to generate highly customized charts with predefined options for each theme.
Script Data Input Types
The new charts with PowerShell advance script accepts two kind of input data:
- Array Of objects: in this case, you have to supply the Obj_Key and Obj_Value parameters to tell the script which properties of the entered objects shall be mapped to the output chart X-axis and Y-axis. This is exactly the same input type of my previous PowerShell charts script.
- Hash Table: just supply a hash table without the need to enter the -Obj_Key and -Obj_Value parameters.
Script Data Themes
A new addition in this wrapper is the -theme option. Instead of being expert on how to customize and play with your chart output, the script provides 7 themes that you chose from by using the -theme parameter. You cannot use the -type parameter when you use the -theme parameter.
$cities = @{London = 7556900; Berlin = 8429900; Madrid = 3213271; Rome = 2726539; Paris = 2188500} Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -chartTheme 1
Script Chart Types
Of course since your generating charts, you can use the -Type parameter to tell the script what type of charts you want to output.
Below is a small list of supported types in this .NET library:
“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”
Note: You cannot use the -Type parameter with the -Theme parameter.
Example
$cities = @{London = 7556900; Berlin = 3429900; Madrid = 3213271; Rome = 2726539; Paris = 2188500} Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -Type Pie Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -Type Candlestick
You can also specify the -Chart_color parameter to color the output chart
Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -Type Column -chart_color green
Script Data Sorting
You can use -Sort option with descending or ascending as shown in the below example
$cities = @{London = 7556900; Berlin = 8429900; Madrid = 3213271; Rome = 2726539; Paris = 2188500} Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -sort dsc
Script data decoration
Things like Chart Title, X-axis title, Y-axis title, legend and more, can be defined as shown below:
$cities = @{London = 7556900; Berlin = 3429900; Madrid = 3213271; Rome = 2726539; Paris = 2188500} Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -showlegend -title_text "people per country" -chartarea_Xtitle "cities" -chartarea_Ytitle "population"
Pie/Doughnut Chart Customization
So if you are using this script with -Type Pie or -Type Doughnut , then you can use the -Show_percentage_pie parameter to instruct the script to show percentages on the chart.
$cities = @{London = 7556900; Berlin = 3429900; Madrid = 3213271; Rome = 2726539; Paris = 2188500} Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -type Doughnut -Show_percentage_pie
Also, sometimes the Pie/Doughnut charts get an ugly look when there is so much data to display, and overlapping text will make it hard to read text on the chart.
One clever solution is to use the -fix_label_alignment switch, which will make the chart appears in 3D and clean all overlapping text.
$cities = @{London = 7556900; Berlin = 3429900; Madrid = 3213271; Rome = 2726539; Paris = 2188500} Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -Type Pie -Show_percentage_pie -fix_label_alignment
Also, if the chart type is pie or doughnut, you can specify a threshold (percentage) that all data values below it, will be shown as one data item called (Others). This is achieved by using the -CollectedThreshold switch.
$cities = @{London = 7556900; Berlin = 3429900; Madrid = 3213271; Rome = 2726539; Paris = 2188500} Get-Corpchart-FullEdition -data $cities -filepath "c:\chart.png" -type Doughnut -CollectedThreshold 16
Download the script
You can Download the charts with PowerShell advance script from Microsoft TechNet Gallery.
Gr8 effort here… im using this script to produce many internal charts for my infrastructure. Love it
I tried this script and it works perfectly
Great Script, i am using your old script, and need your advise to link your script with the sql database.
HI
Great solution!!
question:
I want to create a StackedColumn100. so I have an array with 3 columns (day,Up,Down) ,
I have set -obj_key “day” -obj_value “Up” as a StackedColumn , and works fine
but how do I specify the parameters to do a StackedColumn100 having the column composed by “Up ” and “down”
thanks
Good afternoon!
When I run the script, as examples, nothing happens. It is not displayed error or generated graphic file.
OS: Windows 10
.Net3.5: Ok
MSChart.exe: Ok
Need help.
Well thats strange. Have u tried the light edition?
Não é possível localizar o tipo [system.drawing.fontstyle].
No C:Get-Corpchart-LightEdition.ps1:222 caractere:127
+ … ect system.drawing.font(“ARIAL”,18,[system.drawing.fontstyle]::bold)) …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (system.drawing.fontstyle:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Não é possível localizar o tipo [system.drawing.fontstyle].
No C:Get-Corpchart-LightEdition.ps1:224 caractere:129
+ … t system.drawing.font(“calibri”,16,[system.drawing.fontstyle]::italic …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (system.drawing.fontstyle:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Failed to save chart at c:chart.png
No C:Get-Corpchart-LightEdition.ps1:592 caractere:29
+ Throw “Failed to save chart at $filepath”
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Failed to save chart at c:chart.png:String) [], RuntimeException
+ FullyQualifiedErrorId : Failed to save chart at c:chart.png
PS C:> $cities = @{London=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539;Paris=2188500}
PS C:> .Get-Corpchart-LightEdition -data $cities -obj_key “Name” -obj_value “Population” -filepath “c:chart.png” -type pie
PS: Removing the parameters:
222, [system.drawing.fontstyle] :: bold
224, [system.drawing.fontstyle] :: italic
a png file blank is generated.