Charts and PowerShell !! PowerShell Wrapper “Full Edition”

Check Out the Light Edition of this PowerShell Wrapper : Get-CorpCharts-LightEdition

 

I think one of the most interesting things when writing PowerShell scripts, is to make the results appear in a nice chart or couple of them. 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.

Script Requirements

The script is Filled with examples and information of how to use it. Do not panic if you find the code long or complex for you. Just look at the examples and you will find your way.

Do not forget that you need to install two things before running the script on your machine :

What is different this time?

With the Full PowerShell Wrapper for charts, you will have a wrapper that has two hot additional features compared to the PowerShell Wrapper Light Edition :

  1. The PowerShell Wrapper Light Edition only accepts array of objects as an input data, and requires Obj_Key and Obj_Value parameters to identify X-axis and Y-axis. The PowerShell Wrapper Full Edition adds support to supply  a hashtable as an input data.
  2. The Full Edition Wrapper has a new parameter called -Theme. You can supply 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

1. 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.

Charts_PowerShell

2. HashTable: Just supply a hashtable without the need to enter the -Obj_Key and -Obj_Value parameters.

PowerShell Wrapper2

Script Data Themes

A new addition in this wrapper is the -Theme option.  So 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.

PS C:\> $cities = @{London=7556900; Berlin=8429900; Madrid=3213271; Rome=2726539;Paris=2188500}
PS C:\> 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

PS C:\> $cities = @{London=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539;Paris=2188500}

PS C:\> Get-Corpchart-FullEdition  -data $cities -filepath “c:\chart.png” -Type Pie

PS C:\> Get-Corpchart-FullEdition  -data $cities -filepath “c:\chart.png” -Type Candlestick

You can also specify the -Chart_color parameter to color the output chart

PS C:\> Get-Corpchart-FullEdition  -data $cities -filepath “c:\chart.png” -Type Column -chart_color green

Script Data Sorting

You can use -Sort option with desc or asc as shown in the below example

Example

PS C:\> $cities = @{London=7556900; Berlin=8429900; Madrid=3213271; Rome=2726539;Paris=2188500}
PS C:\> 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:

Example

PS C:\> $cities = @{London=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539;Paris=2188500}
PS C:\> 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

Example

So if you are using this scirpt with -Type “Pie” or “Doughnut”, then you can use the (-Show_percentage_pie) parameter to instruct the script to show percentages on the chart.

PS C:\> $cities = @{London=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539;Paris=2188500}
PS C:\> Get-Corpchart-FullEdition -data $cities -filepath “c:\chart.png” -type Doughnut -Show_percentage_pie

Example

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.

Chart with percentages shown on the pie/doughnut charts. Fixing the overlapping labels on the chart.
PS C:\> $cities = @{London=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539;Paris=2188500}
PS C:\> Get-Corpchart-FullEdition -data $cities -filepath “c:\chart.png” -Type Pie -Show_percentage_pie -fix_label_alignment

Example
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).
PS C:\> $cities = @{London=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539;Paris=2188500}
PS C:\> Get-Corpchart-FullEdition -data $cities -filepath “c:\chart.png” -type Doughnut -CollectedThreshold 16

How to use the script with Array of Objects as an input?

Check examples on the Light Version of this wrapper here.

Download the script

You can Download the script here: Get-CorpCharts-FullEdition

Charts with PowerShell 1

Charts with PowerShell 2

Charts with PowerShell 3

MBX vs Mailboxes

 

DB vs Size

 

Charts with PowerShell 4

 

 

9 comments on “Charts and PowerShell !! PowerShell Wrapper “Full Edition”

  1. Pingback: Charts and PowerShell !! PowerShell Wrapper “Light Edition” | Ammar Hasayen - Blog

  2. Gr8 effort here… im using this script to produce many internal charts for my infrastructure. Love it

  3. Great Script, i am using your old script, and need your advise to link your script with the sql database.

  4. 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

  5. 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.

      • 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

  6. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s