Simple 2-D or 3-D object to pie chart

Hello - I’m a total noob with UD and feel kinda stupid about this one. I have a data collection script that goes through all our workstations and collects mere TCP connection info. I was successful piping the object to a New-UDGrid command, and now I’d like to pipe to Out-UDChartData, for a simple pie or ring chart that shows counts of computers up and counts of computers down. Seems simple, but I don’t know what i am missing in my code.

I have 2 objects that I have been trying to pipe in,

WhatsUpDown (a 3-D array of objects like this):

Name MemberType Definition


Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ComputerName NoteProperty string ComputerName=Computer-name
IsON NoteProperty bool IsON=True

UpDown (a simple 2-D object with 2 values - a count of computers up and a count of computers down:

Name MemberType Definition


Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Down NoteProperty int Down=5
DownLabel NoteProperty string DownLabel=DOWN
Up NoteProperty int Up=11
UpLabel NoteProperty string UpLabel=UP

My code that processes both:

        New-UDChart -Title "Whats Up-Down" -endpoint {
             $UpDown  | Out-UDChartData -Dataset @( 
                            New-UDChartDataset -DataProperty Up -label "Up"
                            New-UDChartDataset -DataProperty Down -Label "Down" 
                            ) -LabelProperty ""
        } -type pie -AutoRefresh -RefreshInterval 60
        
        New-UDChart -Title "Whats Up-Down" -endpoint {
              $WhatsUpDown  | Out-UDChartData -Dataset @( 
                            New-UDChartDataset -DataProperty IsOn -Label "IsOn"
                            ) -LabelProperty ""

        } -type pie -AutoRefresh -RefreshInterval 60

This is what the charts look like:

Thank you so much for taking a look at this. I am sure I am not understanding what the dataset needs.

Never mind - I figured out that I should make a hash table and pass that to out-UDChartData instead of my object. (the hint was here: How to create consistent pie chart labels and colors).

New-UDChart -Title "Whats Up-Down" -type pie -AutoRefresh -RefreshInterval 60 -Endpoint {
            $UpDown = [ordered]@{Up = ($WhatsUpDown | Where-Object {$_.isOn -eq $true}).count;Down = $($WhatsUpDown | Where-Object {$_.isOn -eq $false}).count} #Works
            $UpDown | Out-UDChartData -DataProperty "Values" `
            -BackgroundColor @("green", "red") `
            -LabelProperty "Keys" `
            -HoverBackgroundColor "orange"}

Hope this helps someone else.

1 Like