Created
December 10, 2016 19:44
-
-
Save midnightfreddie/d3e2aab8c7425a53b51da207bc069438 to your computer and use it in GitHub Desktop.
Another ISE scratch item. Adapted from web example to show can conditionally color chart bars based on value. In reply to something on reddit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load the appropriate assemblies | |
[void][Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) | |
[void][Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms.DataVisualization”) | |
# create chart object | |
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart | |
$Chart.Width = 500 | |
$Chart.Height = 400 | |
$Chart.Left = 40 | |
$Chart.Top = 30 | |
# create a chartarea to draw on and add to chart | |
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea | |
$Chart.ChartAreas.Add($ChartArea) | |
$SpaceUsed = @{ | |
C = 0.85 | |
D = 0.6 | |
E = 0.4 | |
} | |
[void]$Chart.Series.Add(“Data”) | |
$Chart.Series[“Data”].Points.DataBindXY($SpaceUsed.Keys, $SpaceUsed.Values) | |
$chart.Series["Data"].Points | ForEach-Object { | |
if ($PSItem.YValues[0] -gt 0.8) { $PSItem.Color = [System.Drawing.Color]::Red } | |
elseif ($PSItem.YValues[0] -gt 0.5) { $PSItem.Color = [System.Drawing.Color]::Yellow } | |
else { $PSItem.Color = [System.Drawing.Color]::Green } | |
} | |
# display the chart on a form | |
$Chart.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor | |
[System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left | |
$Form = New-Object Windows.Forms.Form | |
$Form.Text = “PowerShell Chart” | |
$Form.Width = 600 | |
$Form.Height = 600 | |
$Form.controls.add($Chart) | |
$Form.Add_Shown({$Form.Activate()}) | |
$Form.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment