I create a page with two charts, each of which displays a different representation of the same data. The data is from a vendor’s REST API.
My first attempt:
# Get-Feed: Invoke-WebService; ConvertFrom-Json; return `entries` node
$Data = Get-Feed -Url $Url
# New-UDPage / New-UDRow / New-UDColumn / New-UDLayout omitted for clarity
# assign data to each chart
New-UDMonitor -Title "Running Instances" -Type Line -Endpoint {
$Data | Where-Object { $_.status_type -eq 'Failed' } | Select-Object -Expand 'count' | Out-UDMonitorData
} -DataPointHistory 20 -RefreshInterval 30
New-UDChart -Title "Instances by Status" -Type Doughnut -Endpoint {
$Data | Where-Object { $_.status_type -ne 'Total' } | Out-UDChartData -DataProperty "count" -LabelProperty "status_type" #-DatasetLabel "Status"
} -AutoRefresh -RefreshInterval 30
While this functions, the data is only fetched once, so the graphs never change:
Next, I tried moving the Get-Feed
function within each chart’s block:
#
# position function within block to ensure that it is called on each refresh
#
New-UDMonitor -Title "Running Instances" -Type Line -Endpoint {
Get-Feed -Url $Url | Where-Object { $_.status_type -eq 'Failed' } | Select-Object -Expand 'count' | Out-UDMonitorData
} -DataPointHistory 20 -RefreshInterval 30
New-UDChart -Title "Instances by Status" -Type Doughnut -Endpoint {
Get-Feed -Url $Url | Where-Object { $_.status_type -ne 'Total' } | Out-UDChartData -DataProperty "count" -LabelProperty "status_type" #-DatasetLabel "Status"
} -AutoRefresh -RefreshInterval 30
Unfortunately, this results in an error:
The term ‘Get-Feed’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Why does this happen?
Is there a way to call Get-Feed
once, share the data between both charts, and ensure that Get-Feed
is called on each refresh?
Two ancillary questions:
- How do I get the doughnut chart to use a different color for each status?
- How do I get the doughnut chart to show the data values?