问题
I am trying to create chart by Get-CorpChart-FullEdition script, which I found very good in chart creation.
On the website I found below instruction.
So now, all what you have to do is to give the
$Cities
array to the function as-Data
parameter, and supply the-Obj_Key
parameter as "City_Name", and-Obj_Value
as "City_Population"
I created a hash like this:
$active_inactive = @{}
$red = 15
$orange = 25
$active_inactive['active']= $red
$active_inactive['inactive'] = $orange
. "D:\Auto\Get-Corpchart-LightEdition.ps1" -data $active_inactive -obj_key "Name" -obj_value "Value" -filepath "c:\chart1.png" -type pie
Data in $active_inactive
:
Name Value ---- ----- inactive 7 active 3
Problem is I am getting a blank chart1.png file. It seems like issue with my hashtable.
Can anybody advise me if I am creating the hashtable properly as described above or not?
回答1:
If you wanted to use a hashtable I think you can if you call the .GetEnumarator()
method
which effectively sends each entry in the hash table across the pipeline as a separate object.
. "D:\Auto\Get-Corpchart-LightEdition.ps1" -data $active_inactive.GetEnumerator() -obj_key "Name" -obj_value "Value" -filepath "c:\chart1.png" -type pie
Looking at the code for the light edition of the script the parameter is expecting an [array]
and not a hashtable.
You would be better of creating your own custom objects from that hashtable's data depending on how complex your date would get.
[pscustomobject]@{
State="Active"
Value=15
},[pscustomobject]@{
State="Inactive"
Value=25
}
Tonnes of ways to do this more effectively so the above is just an example.
回答2:
-data
expects an array of objects, not a hashtable.
来源:https://stackoverflow.com/questions/36403010/issue-with-hash-in-chart-creation