Huddled Masses
You can do more than breathe for free...
Browse: Home / Google Charts from PowerShell – Part 1

Google Charts from PowerShell – Part 1

By Joel 'Jaykul' Bennett on 28-Aug-2008

Several people have blogged about using the Google charts api from PowerShell, but everyone seems to be using the “simple” numerical encoding, so I figured that as the first step of my own google chart api wrapper module I would start out by writing up a simple encoder. I’m not posting this to the script repository until I’m done with it — this is just the number encoding function.

But I figured I’d blog it here in case it will help anyone else write the full wrapper module “for” me before I get around to it :) In any case, remember this doesn’t encode numbers higher than 4095, so if you have a bunch of numbers and some of them might be larger than that, you’ll still need to normalize them so they are within that range. I’ll post the function to normalize a series of numbers later this evening, because for some reason I can’t find it right now, but I’m sure I already wrote it ;) .


## Google Chart API extended value encoding function
#########################################################################
function GoogleEncode {
BEGIN {
   ## Google's odydecody is a 64 character array
   $ody = "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
   "R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j",
   "k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2",
   "3","4","5","6","7","8","9","-","."

   ## The actual filter function
   filter encode {
      # we have a hard-coded "overflow" value
      if($_ -ge ($ody.Count * $ody.Count) ) { return "__" }
     
      $y = -1  # $y is a ref variable, so it has to be defined
      $x = [Math]::DivRem( $_, $ody.Count, [ref]$y )
      return "$($ody[$x])$($ody[$y])"
   }
   
   ## Handle numbers as parameters
   foreach($i in $args) {
      $i | encode
   }
}
## Or handle numbers from the pipeline. We don't care :-)
PROCESS {
   if($_ -ne $null) { $_ | encode }
}
}

That’s the whole thing … it’s really only about three lines of code (including the definition of $ody), but the rest is necessary to make it handle parameters or pipeline values. :D

Similar Posts:

  • Arrange – Act – Assert: Intuitive Testing
  • Rich formatting for PowerShell help
  • What Scope Am I In?
  • More Custom Attributes for PowerShell (Parameter Transformation)
  • Working with multiple versions of PowerShell Modules

Posted in Huddled | Tagged APIs, Charting, Extended, Google, PowerShell, Scripting

« Previous Next »

Lijit Search

Tags

.Net .Net 2008 Scripting Games Automation Bugs Design Development Funny Gadgets GeoShell GUI Huddled Masses Internet licensing Microsoft Modules My Software News Personal PInvoke Pipeline Politics PoshCode PoshConsole PowerBoots PowerShell PowerShell Functions PowerTips Rants Recommender Repository Scripting ShowUI Software Solutions Textile Tips User Group UserInterface WalkThrough WebHosting Windows 7 WordPress WPF Xml

About Huddled Masses

This is web site is dedicated to the musings of Joel Bennett (aka Jaykul) about technology, software, software development, the web, and the world.

Any resemblance of the views expressed and the views of my employer, my terminal, or the view out my window are purely coincidental. The resemblance between them and my own views is non-deterministic. The question of the existence of views in the absence of anyone to hold them is left as an exercise for the reader.

P.S.: I occasionally link to things I think are great. When I do, I occasionally find a "referral code" so I can make a little cash. I promise that I don't link to anything just because of that cash (I wouldn't cross the street for the amount of cash those links bring in, never mind write a whole blog post) ... but I do not promise that things I link to will stay great as time passes, nor that you will agree with me about their greatness!

Archives

  • January 2012
  • October 2011
  • August 2011
  • July 2011
  • June 2011
  • March 2011
  • February 2011
  • January 2011
  • November 2010
  • August 2010

Copyright © 2012 Joel Bennett.

Powered by WordPress and Hybrid.