PSWriteWord icon indicating copy to clipboard operation
PSWriteWord copied to clipboard

Showing values in chart

Open oliwex opened this issue 4 years ago • 7 comments


$userObjects=Get-ADUser -Filter *
$chart = $userObjects | Group-Object Department | Select-Object Name, @{Name = "Values"; Expression = { [math]::round(((($_.Count) / $userObjects.Count) * 100), 2) } } | Where-Object { $_.Values -ge 1 } | Sort-Object -Descending Values
Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Chart" -Supress $true
Add-WordPieChart -WordDocument $reportFile -ChartName 'Chartk'-ChartLegendPosition Bottom -ChartLegendOverlay $false -Names $([array]$chart.Name) -Values $([array]$chart.Values)

I want to show values in chart legend or on the chart image. How to do this?

oliwex avatar Aug 12 '21 11:08 oliwex

Basically, you would need to build Names with values inside.

$userObjects = Get-ADUser -Filter *
$chart = $userObjects | Group-Object Department | Select-Object Name, @{Name = "Values"; Expression = { [math]::round(((($.Count) / $userObjects.Count) * 100), 2) } } | Where-Object { $.Values -GE 1 } | Sort-Object -Descending Values
Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Chart" -Supress $true

[array] $Names = foreach ($O in $Chart) {
    "$($O.Name) ($($O.Values))"
}

Add-WordPieChart -WordDocument $reportFile -ChartName 'Chartk'-ChartLegendPosition Bottom -ChartLegendOverlay $false -Names $Names -Values $([array]$chart.Values)

PrzemyslawKlys avatar Aug 12 '21 19:08 PrzemyslawKlys

But is it possible to simplify that by adding more options to cmdlet. Like adding values to pie like: percent values or simple values or something?

oliwex avatar Aug 13 '21 07:08 oliwex

image or percent values image

oliwex avatar Aug 13 '21 07:08 oliwex

Yes, you can create PR to do it for you.

PrzemyslawKlys avatar Aug 13 '21 07:08 PrzemyslawKlys

I try to do it with calculated field but no results( to simplify my code). But, do you know how to do the second version of graph from my images nad paste the code here?

oliwex avatar Aug 13 '21 07:08 oliwex

You just need to calculate the percentage yourself. My code won't do it for you.

PrzemyslawKlys avatar Aug 13 '21 07:08 PrzemyslawKlys

I know how to calculate it but dont know how to pass it into pie like in the 2 image

oliwex avatar Aug 13 '21 07:08 oliwex