The docs for the new Google Charts API include a Javascript function
called simpleEncode. It demonstrates encoding a data set into a
“Simple encoding” as expected by the API.......followed by a PHP
function which does the same thing.
function simpleEncode($values, $maxValue=-1)
{
$simpleEncoding =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$simpleLength = strlen($simpleEncoding)-1;
if ($maxValue < 0) $maxValue = max($values);
$chartData = 's:';
foreach ($values as $currentValue) {
if (is_numeric($currentValue) && $currentValue >= 0) {
$chartData .= $simpleEncoding[round($simpleLength *
$currentValue / $maxValue)];
} else {
$chartData .= '_';
}
}
return $chartData;
}
It returns a string representing the Simple encoding of your
datapoints, prepended by the ’s:’ specified in the Google Charts API.
In short, it does exactly the same thing as the sample Javascript
function provided in the API docs, only it doesn’t require you to
specify a max value.
So
print simpleEncode(array(1, 3, 11, 8, 4, 2, 9))
returns ’s:GR9sWLy’. it is correct and good.
simpleEncode (Array(39, 43, 40, 41))
returns ’s:3956’.Should return ’s:nrop’
Help me please. Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Chart API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-chart-api?hl=en
-~----------~----~----~----~------~----~------~--~---