function
GooglePieChart {
Param
(
$Data
= @{
'Yin'
=1;
'Yang'
=1},
$HeaderRow
=
[ordered]
@{
'Topping'
=
'string'
;
'Slices'
=
'number'
},
$options
= @{
"title"
=
"Test Title"
;
"width"
=500;
"height"
=500;
"is3D"
=
"true"
;
'legend'
=
'bottom'
;
"titleTextStyle"
=@{
"color"
=
"black"
;
"fontName"
=
'"Verdana"'
;
"fontsize"
=12};
'backgroundColor'
=
'white'
;
'pieSliceText'
=
'percentage'
}
)
$HTML
=
@"
<html>
<head>
<!--Load the AJAX API-->
<!-- background-color:#b0e0e6; -->
<style>
.left
{
float:left;
width:300px;
}
.right
{
float:right;
width:300px;
}
</style>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart','table']});
google.load('visualization', '1.0', {'packages':['corechart','table']});
//google.load('visualization', '1.0', {'packages':['piechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
"@
$columns
=
$HeaderRow
$HTML
+=
$columns
.GetEnumerator() | % {
"data.addColumn('$($_.Value)','$($_.Name)');`n"
; }
if
(
$data
.Gettype().Name
-eq
"OrderedDictionary"
)
{
$HTML
+=
"data.addRows($($data.count));`n"
$i
=0;
$HTML
+=
$data
.GetEnumerator() | % {
"data.setValue($i,0,'$($_.Name)');`ndata.setValue($i,1,$($_.Value));`n"
;
$i
++; }
}
elseif
(
$data
[0]
-is
"object[]"
) {
$JSON
=
ConvertTo-JSON
-compress
$Data
$HTML
+=
"data.addRows($JSON);`n"
}
else
{
$HTML
+=
"data.addRows($($data.count));`n"
$i
=0;
$a
=@();
$a
+=
$columns
.keys | %{
$_
};
$HTML
+=
$data
| % {
"data.setValue($i,0,'$($_.$($a[0]))');`ndata.setValue($i,1,$($_.$($a[1])));`n"
;
$i
++; }
}
$HTML
+=
"var options =$($options | ConvertTo-Json );"
$HTML
+=
@"
// Instantiate and draw our chart, passing in some options.
// alert('Test')
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
var chart2 = new google.visualization.BarChart(document.getElementById('chart_div2'));
chart2.draw(data, options);
var visualization = new google.visualization.Table(document.getElementById('table'));
visualization.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div>
<div class="left" id="chart_div"></div>
<div class="right" id="chart_div2"></div>
</Div>
<div id="table"></div>
<div id="Links">
<p>If you don't see anything try a refresh.</P>
<!-- <div><a href=""></a> </div> -->
</div>
</body>
</html>
"@
write-output
$HTML
}
$Source
=
[ordered]
@{'Apples
'= 3;'
Onions
'=1;'
Olives
'= 1;'
Zucchini
'=1;'
Pepperoni
'= 2}
#$Source = @(('
Mushrooms
', 3),('
pie
',1),('
Olives
',1),('
Zucchini
',1),('
Pepperoni
', 2))
#$source = @([PSCustomObject][ordered]@{"Fruit"="Apple";"Amount"="2"},[PSCustomObject][ordered]@{"Fruit"="orange";"Amount"="5"})
$ObjectHeader =[ordered]@{'
Fruit
'='
string
';'
Amount
'='
number'}
$html
= GooglePieChart
$Source
-HeaderRow
$ObjectHeader