Thursday, March 1, 2007

Another PowerGadgets example

I've blogged a few times before about the 2007 Microsoft Scripting Games.  There was 4 categories this year, and I originally thought I was going to map all the data like I previously did.  Instead, I though I'd do something different: represent the number of participants per country per category in a line graph using PowerGadgets.

Here's the finished product: all countries (with more than 5 total entrants).


psaentries: PowerShell advanced, psbentries: PowerShell beginner, vbaentries: VBScript advanced,  and vbbentries: VBScript beginner.  total is just the sum of the former 4 values.

Here's an example of the 'mouse-over' features.  What I did here, was put my mouse over  psaentries in the legend box: PowerShell advanced entries.

Here's another advanced feature where I add a "data grid", so I can view all the data in a table format just below the graph:data grid option.

And finally, one more advanced feature where I do a mouse-over of a particular data point, and I get: a popup tooltip.

To keep the graph "less busy", I've only added countries who had a total number of participants of 5 or more.

All the entries for each category are here: VBScript beginner, VBScript advanced, PowerShell beginner, and PowerShell advanced.

Inspired by /\/\o\/\/, here's the script I used:





foreach ($category in $categories){
$wc = new-Object System.Net.WebClient
$nl = $wc.DownloadString("$url")
$r = [regex]'l">(.*?)</p'
$m = $r.Matches($nl)
$l = $m |% {$_.groups[1].value}
$list = @()
foreach ($i in 13..($l.count -1) ) {
$Record = new-Object -typename System.Object
$Record | add-Member -memberType noteProperty -name Name -Value $m[$i].groups[1].value
[void] $foreach.MoveNext()
$Record | add-Member -memberType noteProperty -name Country -Value $m[$foreach.current].groups[1].value
1..10 |% {[void] $foreach.MoveNext();$Record | add-Member -memberType noteProperty -name "E$_" -Value $m[$foreach.current].groups[1].value}
[void] $foreach.MoveNext();$Record | add-Member -memberType noteProperty -name "Total" -Value $m[$foreach.current].groups[1].value
$list += $record
$list|group Country|`
%{if($countries[$] -eq $null){$countries[$]="0,0,0,0,0"}
set-variable country_val$z $cur_count




foreach ($arr_country in $arr_countries){
$record=new-object -typename system.object
$record|add-member -membertype noteproperty -name Country -value $arr_country
$record|add-member -membertype noteproperty -name PSAEntries -value $cur_country0
$record|add-member -membertype noteproperty -name PSBEntries -value $cur_country1
$record|add-member -membertype noteproperty -name VBAEntries -value $cur_country2
$record|add-member -membertype noteproperty -name VBBEntries -value $cur_country3
$record|add-member -membertype noteproperty -name Total -value $cur_country4

$listing|?{$_.Total -ge 5}|`
out-chart -palette highcontrast -label country -values psaentries,psbentries,vbaentries,vbbentries,total -AllSeries_Gallery Lines -AllSeries_PointLabels_Visible false

[end code]

(I'm still trying to figure out blogspot code formatting...  Leave a comment if you'd like me to send you the script.)