Google Charts

From Second Life Wiki
Revision as of 17:35, 31 December 2007 by Dedric Mauriac (talk | contribs)
Jump to navigation Jump to search

<lsl> string simpleEncoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; string simpleEncode(list values) {

   string text = "";
   float max = llListStatistics(LIST_STAT_MAX, values);
   
   integer count = llGetListLength(values);
   
   integer index;
   
   for(index = 0; index < count; index++)
   {
       integer value = llList2Integer(values, index);
       if(value < 0)
           text += "_";
       else
       {
           float percent = value / max;
           value = llFloor(percent * 61);
           text += llGetSubString(simpleEncoding, value, value);
       }
   }
   return text;

} string chartUrl(list values, list captions) {

   integer i;
   integer n = llGetListLength(captions);
   string url = "http://chart.apis.google.com/chart";
   url += "?chs=200x125";
   url += "&chd=s:" + simpleEncode(values);
   url += "&cht=lc";
   url += "&chxt=x,y";
   url += "&chxl=0:";
   for(i = 0; i < n; i++)
       url += "|" + llEscapeURL(llList2String(captions, i));
   url += "|1:||" + (string)llCeil(llListStatistics(LIST_STAT_MAX, values));
   return url;

} </lsl>