A bar chart puts one bar per value beside its label, with the value on the right. Set a maximum to draw each bar as a share of it, and thresholds to colour the bars that cross them.
Install-Module ConsoleMonster -Scope CurrentUser# Draw a bar per value, coloured where it crosses a warning or critical threshold.
Import-Module -Name ConsoleMonster
# Data: invented disk use per server, in percent of capacity.
$disks = @(
[pscustomobject] @{ Server = 'fs01'; Used = 62 }
[pscustomobject] @{ Server = 'fs02'; Used = 81 }
[pscustomobject] @{ Server = 'sql01'; Used = 93 }
[pscustomobject] @{ Server = 'web01'; Used = 40 }
[pscustomobject] @{ Server = 'web02'; Used = 57 }
)
# Layout: Property picks the value, Label the name; Maximum makes each bar a share of 100.
$chartOptions = @{
Property = 'Used'
Label = 'Server'
Unit = '%'
Maximum = 100
Warning = 80
Critical = 90
}
$chart = $disks | New-ConsoleChart @chartOptions
# Behaviour: print once.
$chart | Show-ConsoleFull program
# Draw a bar per value, coloured where it crosses a warning or critical threshold.
Import-Module -Name ConsoleMonster
# Data: invented disk use per server, in percent of capacity.
$disks = @(
[pscustomobject] @{ Server = 'fs01'; Used = 62 }
[pscustomobject] @{ Server = 'fs02'; Used = 81 }
[pscustomobject] @{ Server = 'sql01'; Used = 93 }
[pscustomobject] @{ Server = 'web01'; Used = 40 }
[pscustomobject] @{ Server = 'web02'; Used = 57 }
)
# Layout: Property picks the value, Label the name; Maximum makes each bar a share of 100.
$chartOptions = @{
Property = 'Used'
Label = 'Server'
Unit = '%'
Maximum = 100
Warning = 80
Critical = 90
}
$chart = $disks | New-ConsoleChart @chartOptions
# Behaviour: print once.
$chart | Show-ConsoleRun: ./bar-chart.ps1
dotnet new console -n DiskChart
cd DiskChart
dotnet add package ConsoleMonster// Draw a bar per value, coloured where it crosses a warning or critical threshold.
using ConsoleMonster;
using ConsoleMonster.Widgets;
// Data: invented disk use per server, in percent of capacity.
var disks = new Disk[]
{
new("fs01", 62),
new("fs02", 81),
new("sql01", 93),
new("web01", 40),
new("web02", 57)
};
// Layout: one bar per server; Maximum makes each bar a share of 100.
BarChart chart = new BarChart
{
Unit = "%",
Maximum = 100,
Warning = 80,
Critical = 90
};
foreach (var disk in disks)
chart.Add(disk.Server, disk.Used);
// Behaviour: print once.
Terminal.Write(chart);
record Disk(string Server, int Used);Full program
// Draw a bar per value, coloured where it crosses a warning or critical threshold.
using ConsoleMonster;
using ConsoleMonster.Widgets;
// Data: invented disk use per server, in percent of capacity.
var disks = new Disk[]
{
new("fs01", 62),
new("fs02", 81),
new("sql01", 93),
new("web01", 40),
new("web02", 57)
};
// Layout: one bar per server; Maximum makes each bar a share of 100.
BarChart chart = new BarChart
{
Unit = "%",
Maximum = 100,
Warning = 80,
Critical = 90
};
foreach (var disk in disks)
chart.Add(disk.Server, disk.Used);
// Behaviour: print once.
Terminal.Write(chart);
record Disk(string Server, int Used);Run: dotnet run
dotnet new console -n DiskChart
cd DiskChart
dotnet add package ConsoleMonster// Draw a bar per value, coloured where it crosses a warning or critical threshold.
using ConsoleMonster;
using ConsoleMonster.Widgets;
// Data: invented disk use per server, in percent of capacity.
var disks = new Disk[]
{
new("fs01", 62),
new("fs02", 81),
new("sql01", 93),
new("web01", 40),
new("web02", 57)
};
// Layout: one bar per server; Maximum makes each bar a share of 100.
BarChart chart = Ui.BarChart().Unit("%").Maximum(100).Warning(80).Critical(90);
foreach (var disk in disks)
chart.Add(disk.Server, disk.Used);
// Behaviour: print once.
chart.Show();
record Disk(string Server, int Used);
Full program
// Draw a bar per value, coloured where it crosses a warning or critical threshold.
using ConsoleMonster;
using ConsoleMonster.Widgets;
// Data: invented disk use per server, in percent of capacity.
var disks = new Disk[]
{
new("fs01", 62),
new("fs02", 81),
new("sql01", 93),
new("web01", 40),
new("web02", 57)
};
// Layout: one bar per server; Maximum makes each bar a share of 100.
BarChart chart = Ui.BarChart().Unit("%").Maximum(100).Warning(80).Critical(90);
foreach (var disk in disks)
chart.Add(disk.Server, disk.Used);
// Behaviour: print once.
chart.Show();
record Disk(string Server, int Used);
Run: dotnet run
fs01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━────────────────────────── 62% fs02 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━───────────── ▲ 81% sql01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━───── ✗ 93% web01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━───────────────────────────────────────── 40% web02 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━───────────────────────────── 57%
fs01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━────────────────────────── 62% fs02 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━───────────── ▲ 81% sql01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━───── ✗ 93% web01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━───────────────────────────────────────── 40% web02 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━───────────────────────────── 57%
Disk use for five invented servers at 80 columns.
-Propertynames the numeric property and-Labelthe one that names each bar. An ordered hashtable oflabel = valueworks too, with-InputObject.- Without
-Maximumthe longest bar fills the width. With it,100with-Unit '%'reads as a percentage of capacity. -Warningand-Criticalcolour a bar amber or red and mark it once its value reaches them, so the problem stands out without a legend or colour.- In C#, set
Maximum,Unit,WarningandCriticalon aBarChartand callAdd(label, value)per bar.
Next
- Show nested data as a tree: the same servers grouped by site.
- Pipeline charts: the other chart types and the data they take.
- Your first report: bars in a panel under a table.