Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Showing values in chart #66

Open
oliwex opened this issue Aug 12, 2021 · 7 comments
Open

Showing values in chart #66

oliwex opened this issue Aug 12, 2021 · 7 comments

Comments

@oliwex
Copy link

oliwex commented Aug 12, 2021

$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?

@PrzemyslawKlys
Copy link
Member

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)

@oliwex
Copy link
Author

oliwex commented Aug 13, 2021

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
Copy link
Author

oliwex commented Aug 13, 2021

image
or percent values
image

@PrzemyslawKlys
Copy link
Member

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

@oliwex
Copy link
Author

oliwex commented Aug 13, 2021

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?

@PrzemyslawKlys
Copy link
Member

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

@oliwex
Copy link
Author

oliwex commented Aug 13, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants