-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample05.ps1
More file actions
88 lines (74 loc) · 3.48 KB
/
Example05.ps1
File metadata and controls
88 lines (74 loc) · 3.48 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<#
.SYNOPSIS
Example 05 - Basic Stacked Bar Chart
.DESCRIPTION
This example demonstrates how to create a basic Stacked Bar Chart using the AsBuiltReport.Chart module.
The chart displays datastore utilization (used vs. free space) for a set of vSphere datastores.
#>
[CmdletBinding()]
param (
[System.IO.DirectoryInfo] $Path = (Get-Location).Path,
[string] $Format = 'png'
)
<#
Starting with PowerShell v3, modules are auto-imported when needed. Importing the module here
ensures clarity and avoids ambiguity.
#>
# Import-Module AsBuiltReport.Chart -Force -Verbose:$false
<#
Since the chart output is a file, specify the output folder path using $OutputFolderPath.
#>
$OutputFolderPath = Resolve-Path $Path
<#
Define the data to be displayed in the chart.
For a Stacked Bar Chart:
- $Values is an array of double arrays. Each inner array represents one bar and contains the
values for all stack segments (categories) for that bar, in the same order as $LegendCategories.
The number of inner arrays should match $Labels.Length, and the length of each inner array
should match $LegendCategories.Length.
- $Labels contains the label for each bar (X-axis entries).
- $LegendCategories contains the label for each series (stack segments shown in the legend).
In this example:
- Bar 1 = datastore-01: 800 GB Used, 200 GB Free
- Bar 2 = datastore-02: 600 GB Used, 400 GB Free
- Bar 3 = datastore-03: 1500 GB Used, 500 GB Free
- Bar 4 = datastore-04: 300 GB Used, 700 GB Free
#>
$ChartTitle = 'Datastore Capacity (GB)'
$Labels = @('datastore-01', 'datastore-02', 'datastore-03', 'datastore-04')
$LegendCategories = @('Used Space', 'Free Space')
# Each inner array represents one bar's segment values, ordered by $LegendCategories.
$Values = @(@(800, 200), @(600, 400), @(1500, 500), @(300, 700))
<#
The New-StackedBarChart cmdlet generates the Stacked Bar Chart image.
-Title : Sets the chart title displayed at the top of the image.
-Values : Array of double arrays. Each inner array represents one bar and contains
the values for each stack segment (category) for that bar, ordered to match
$LegendCategories. The number of inner arrays should equal the number of
$Labels.
-Labels : Array of label strings, one per bar (X-axis entries).
-LegendCategories : Array of category names shown in the legend (one per value position in each inner array).
-EnableLegend : Enables the legend on the chart.
-LabelXAxis : Label for the X-axis.
-LabelYAxis : Label for the Y-axis.
-Format : Output file format (e.g. png, jpg, svg).
-OutputFolderPath : Directory where the generated chart file will be saved.
-Width : Width of the output image in pixels.
-Height : Height of the output image in pixels.
-AreaOrientation : Orientation of the bars (Horizontal or Vertical).
-Filename : Name of the output file (without extension).
#>
New-StackedBarChart `
-Title $ChartTitle `
-Values $Values `
-Labels $Labels `
-LegendCategories $LegendCategories `
-EnableLegend `
-LabelXAxis 'Datastore' `
-LabelYAxis 'Capacity (GB)' `
-Format $Format `
-OutputFolderPath $OutputFolderPath `
-Width 700 `
-Height 450 `
-AreaOrientation Horizontal `
-Filename 'Example05-StackedBarChart'