Making a Pie Chart with SQL Output

I have made some really cool pie charts with Adam’s tutorials on YouTube, but they all seem to center around windows items with powershell properties. Is it possible to generate a pie chart with SQL output that is stored in a variable?

My data is in a variable called $cache:piedata and the output is like this:
service entry_time_stamp


Service1 11/22/2019 4:00:30 PM
Service1 11/22/2019 4:34:37 PM
Service1 11/22/2019 4:41:47 PM
Service2 11/22/2019 4:49:11 PM

I want to be able to auto generate the pie chart based on the number of service items that appear and group them by that number, but I can’t seem to do it. :frowning:

This is what I tried, but no dice. Any hints would be awesome :smiley:

$Monitoring = New-UDPage -Name "Monitoring" -Icon television -Content { 
  
    New-UDChart -Title "Pie Test" -Type Pie -Endpoint {  
      $cache:piedata | Out-UDChartData -Dataset $cache:piedata -LabelProperty service -DatasetLabel "service"  
        }  
            }

You need to group your services by name. I didn’t actually test this but it should be close.

$Monitoring = New-UDPage -Name "Monitoring" -Icon television -Content { 
  
    New-UDChart -Title "Pie Test" -Type Pie -Endpoint {  
      $cache:piedata | Group-Object service | Out-UDChartData -DataProperty "count" -LabelProperty Name -DatasetLabel "service"  
        }  
            }
1 Like

I have a half circle doughnut chart coming from SQL…here is my code:-

 $LegendOptions = New-UDChartLegendOptions -LabelFontSize 18 -Position bottom -LabelUsePointStyle $true -LabelFontStyle bold
   $tooltips = New-UDChartTooltipOptions -TitleFontSize 18 -TitleFontStyle bold -BodyFontSize 18 -FooterFontSize 18
   $title7 = New-UDChartTitleOptions -Display top -FontSize 16 -FontColor "#ffffff" -FontStyle bold -Text "Cream, Goods, Milk 7 days"
   $chartops =  New-UDDoughnutChartOptions -CutoutPercentage 50 -Rotation 3.14159 -Circumference 3.14159 -AnimateRotate $false -AnimateScale $false -LegendOptions $LegendOptions -TooltipOptions $tooltips -TitleOptions $title7
   New-UDChart -Type "Doughnut" -Endpoint {
   $Session:ChartCGM7 | Out-UDChartData -LabelProperty "ProType"  -Dataset @(
   New-UDChartDataset -Label "ProType" -DataProperty "Total" -BackgroundColor @("#2C44E8", "#FF4239", "#6FFF37") -BorderColor @("#000000", "#000000", "#000000") -HoverBackgroundColor @("Blue","Red","Green") -BorderWidth 1
   ) } -Options $chartops
1 Like