View Single Post
 12-14-2007, 05:08 PM #1 (permalink) Karl The Reckoner        Join Date: Sep 2007 Posts: 437 Thanks: 22 Google chart extended data encoding help Hey, I need some help with an algorithm for the GoogleChart "wrappers" that I am working with. I'm in the process of writing the extended data encoding algorithm, I've come up with something that works, but I now there is a better solution to it using math. Here is the code that I came up with, it all works and should prove to be a good reference. php Code: `public static function convert(\$nValue)    {        // This code will be slow, and should be replaced with a mathematical algorithm                assert(\$nValue >= 0);                                    \$aMask = array('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', '-', '.');                \$iLength = count(\$aMask);                             \$iCount = 0;                            for (\$i = 0; \$i < \$iLength; \$i++)        {                     for (\$j = 0; \$j < \$iLength; \$j++)            {                if (\$nValue == \$iCount)                {                    return \$aMask[\$i] . \$aMask[\$j];                }                \$iCount++;            }        }                                    return '__';    }` Any help with this would be greatly appreciated. Here's the link to Google's documentation on the extended encoding: http://code.google.com/apis/chart/#extended One last note, I'm not sure if I was on the right track, but I was thinking that the math algorithm would need to use a base64 style numbering system, replacing each of the 64 possible values with the values provided by Google and then somehow do the math (it just all got too much for me). __________________ Any fool can write code that a computer can understand. Good programmers write code that humans can understand.