Private/Invoke-ChartCustomize.ps1
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
function Invoke-ChartCustomize { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [Object]$Sender, [Parameter(Mandatory = $true)] [Object]$EventArgs, [String]$Suffix, [ValidateSet('X', 'Y', 'Y2')] [String[]]$Axis ) $Chart = $Sender -as [System.Windows.Forms.DataVisualization.Charting.Chart] if ($null -ne $Chart) { if ($Axis -contains 'X') { $Chart.ChartAreas[0].AxisX.CustomLabels | ForEach-Object { if ($null -ne $_.Text) { [DateTime]$Date = [DateTime]::MinValue if ([DateTime]::TryParseExact($_.Text, "d. MMM HH:mm", [System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::None, [ref]$Date)) { if ($Date.Hour -eq 0 -and $Date.Minute -eq 0) { $_.Text = $Date.ToString("d. MMM") } else { $_.Text = $Date.ToString("HH:mm") } } elseif ([DateTime]::TryParseExact($_.Text, "M/d/yyyy", [System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::None, [ref]$Date)) { $_.Text = $Date.ToString("MMM \'yy") } } } } if ($Axis -contains 'Y') { $Chart.ChartAreas[0].AxisY.CustomLabels | ForEach-Object { $Label = $_ if ($null -ne $_.Text) { switch ([long]$Label.Text) { {$_ -ge 1000000000000000} { $Label.Text = "{0:#.##} PB$Suffix" -f [math]::Round($_ / 1000000000000000, 2) break } {$_ -ge 1000000000000} { $Label.Text = "{0:#.##} TB$Suffix" -f [math]::Round($_ / 1000000000000, 2) break } {$_ -ge 1000000000} { $Label.Text = "{0:#.##} GB$Suffix" -f [math]::Round($_ / 1000000000, 2) break } {$_ -ge 1000000} { $Label.Text = "{0:#.##} MB$Suffix" -f [math]::Round($_ / 1000000, 2) break } {$_ -ge 1000} { $Label.Text = "{0:#.##} KB$Suffix" -f [math]::Round($_ / 1000, 2) break } {$_ -eq 0} { $Label.Text = '' break } default { $Label.Text = "{0:#.##} B$Suffix" -f $_ break } } } } } if ($Axis -contains 'Y2') { $Chart.ChartAreas[0].AxisY2.CustomLabels | ForEach-Object { $Label = $_ if ($null -ne $_.Text -and $_.Text -eq "-0.0") { $Label.Text = "" } } } } } function Invoke-ChartCustomizeLegend { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [Object]$Sender, [Parameter(Mandatory = $true)] [Object]$EventArgs ) $Chart = $Sender -as [System.Windows.Forms.DataVisualization.Charting.Chart] if ($null -ne $Chart) { $LegendItems = $EventArgs.LegendItems -as [System.Windows.Forms.DataVisualization.Charting.LegendItemsCollection] $LegendItems | ForEach-Object { $_.Cells[0].SeriesSymbolSize = [System.Drawing.Size]::New($_.MarkerSize * 12, $_.MarkerSize * 12) } } } function Invoke-ChartPostPaint { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [Object]$Sender, [Parameter(Mandatory = $true)] [Object]$EventArgs ) $Chart = $Sender -as [System.Windows.Forms.DataVisualization.Charting.Chart] if ($null -ne $Chart) { $EventArgs.ChartGraphics.Graphics.DrawLine([System.Drawing.Pen]::New([System.Drawing.ColorTranslator]::FromHtml("#E8E8E8")), 510,10,510,110) $EventArgs.ChartGraphics.Graphics.DrawLine([System.Drawing.Pen]::New([System.Drawing.ColorTranslator]::FromHtml("#E8E8E8")), 803,10,803,110) } } |