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:

What is different this time?

Compared to my previous PowerShell charts script, this charts with PowerShell advance script adds the following two features:

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

Charts with PowerShell advance techniques

  • Hash Table: just supply a hash table without the need to enter the -Obj_Key and -Obj_Value parameters.

Charts with PowerShell advance techniques

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.

Charts with PowerShell advance techniques

Charts with PowerShell advance techniques

Charts with PowerShell advance techniques

Charts with PowerShell advance techniques

Charts with PowerShell advance techniques

Charts with PowerShell advance techniques