|
| 1 | +<# |
| 2 | + .SYNOPSIS |
| 3 | + Example 02 - Pie Chart with Legend, Custom Colors and Border |
| 4 | +
|
| 5 | + .DESCRIPTION |
| 6 | + This example demonstrates how to create a Pie Chart with additional visual options, including: |
| 7 | + - An enabled legend with custom alignment and orientation |
| 8 | + - A custom hex color palette |
| 9 | + - A chart border |
| 10 | + - Adjusted title and label font sizes |
| 11 | + - Custom chart dimensions |
| 12 | +
|
| 13 | + The chart displays a server operating system distribution report. |
| 14 | +#> |
| 15 | + |
| 16 | +[CmdletBinding()] |
| 17 | +param ( |
| 18 | + [System.IO.DirectoryInfo] $Path = (Get-Location).Path, |
| 19 | + [string] $Format = 'png' |
| 20 | +) |
| 21 | + |
| 22 | +<# |
| 23 | + Starting with PowerShell v3, modules are auto-imported when needed. Importing the module here |
| 24 | + ensures clarity and avoids ambiguity. |
| 25 | +#> |
| 26 | + |
| 27 | +# Import-Module AsBuiltReport.Chart -Force -Verbose:$false |
| 28 | + |
| 29 | +<# |
| 30 | + Since the chart output is a file, specify the output folder path using $OutputFolderPath. |
| 31 | +#> |
| 32 | + |
| 33 | +$OutputFolderPath = Resolve-Path $Path |
| 34 | + |
| 35 | +<# |
| 36 | + Define the data to be displayed in the chart. |
| 37 | + In a real-world scenario these values would come from your infrastructure query. |
| 38 | +#> |
| 39 | + |
| 40 | +$ChartTitle = 'Server OS Distribution' |
| 41 | +$Values = @(85, 60, 30, 15) |
| 42 | +$Labels = @('Windows Server 2022', 'Windows Server 2019', 'RHEL 9', 'Ubuntu 22.04') |
| 43 | + |
| 44 | +<# |
| 45 | + A custom hex color palette can be used to match corporate branding or improve readability. |
| 46 | + Each color corresponds to a slice in the order they appear in $Values. |
| 47 | +#> |
| 48 | + |
| 49 | +$CustomColors = @('#0078D4', '#00B7C3', '#E74C3C', '#F39C12') |
| 50 | + |
| 51 | +<# |
| 52 | + The New-PieChart cmdlet generates the Pie Chart image. |
| 53 | +
|
| 54 | + -Title : Sets the chart title. |
| 55 | + -TitleFontSize : Sets the font size of the title in points. |
| 56 | + -TitleFontBold : Renders the title in bold. |
| 57 | + -Values : Array of numeric values, one per slice. |
| 58 | + -Labels : Array of label strings corresponding to each value. |
| 59 | + -LabelFontSize : Sets the font size of the slice labels. |
| 60 | + -LabelDistance : Controls how far labels are placed from the chart center (0.5-0.9). |
| 61 | + -EnableLegend : Enables the legend on the chart. |
| 62 | + -LegendAlignment : Positions the legend (e.g. UpperRight, LowerCenter). |
| 63 | + -LegendOrientation : Sets legend layout direction (Vertical or Horizontal). |
| 64 | + -LegendFontSize : Sets the legend text font size in points. |
| 65 | + -EnableChartBorder : Draws a border around the chart area. |
| 66 | + -ChartBorderColor : Sets the border color. |
| 67 | + -ChartBorderSize : Sets the border thickness in pixels. |
| 68 | + -EnableCustomColorPalette : Enables use of the custom color palette. |
| 69 | + -CustomColorPalette : Array of hex color strings for each slice. |
| 70 | + -Width : Output image width in pixels. |
| 71 | + -Height : Output image height in pixels. |
| 72 | + -Format : Output file format (e.g. png, jpg, svg). |
| 73 | + -OutputFolderPath : Directory where the generated chart file will be saved. |
| 74 | + -Filename : Name of the output file (without extension). |
| 75 | +#> |
| 76 | + |
| 77 | +New-PieChart ` |
| 78 | + -Title $ChartTitle ` |
| 79 | + -TitleFontSize 18 ` |
| 80 | + -TitleFontBold ` |
| 81 | + -Values $Values ` |
| 82 | + -Labels $Labels ` |
| 83 | + -LabelFontSize 13 ` |
| 84 | + -LabelDistance 0.7 ` |
| 85 | + -EnableLegend ` |
| 86 | + -LegendAlignment UpperRight ` |
| 87 | + -LegendOrientation Vertical ` |
| 88 | + -LegendFontSize 12 ` |
| 89 | + -EnableChartBorder ` |
| 90 | + -ChartBorderColor Black ` |
| 91 | + -ChartBorderSize 2 ` |
| 92 | + -EnableCustomColorPalette ` |
| 93 | + -CustomColorPalette $CustomColors ` |
| 94 | + -Width 600 ` |
| 95 | + -Height 400 ` |
| 96 | + -Format $Format ` |
| 97 | + -OutputFolderPath $OutputFolderPath ` |
| 98 | + -Filename 'Example02-PieChart-Advanced' |
0 commit comments