Difference between revisions of "Google Charts"
Jump to navigation
Jump to search
(<.< i couldn't resist) |
|||
Line 5: | Line 5: | ||
[http://chart.apis.google.com/chart?chs=200x125&chd=s:99WPHmWPPWHetWe1mtmmemmte&cht=lc&chxt=x,y&chxl=0:|4AM|4PM|4AM|1:||8 Example] | [http://chart.apis.google.com/chart?chs=200x125&chd=s:99WPHmWPPWHetWe1mtmmemmte&cht=lc&chxt=x,y&chxl=0:|4AM|4PM|4AM|1:||8 Example] | ||
<lsl> | <lsl>string simpleEncode(list values, float min, float max) | ||
string simpleEncode(list values) | |||
{ | { | ||
string text = ""; | string text = ""; | ||
float max = | float range = 244 / (min - max);//4 * 61 | ||
integer index = llGetListLength(values); | |||
while(index) | |||
{ | { | ||
integer | integer type = llGetListEntryType(values, --index); | ||
if( | if(type == TYPE_FLOAT || type == TYPE_INTEGER) | ||
text + | text = llGetSubString(llIntegerToBase64((integer)(range * (min - llList2Float(values, index)))), 4, 4) + text; | ||
else | else | ||
text = "_" + text; | |||
} | } | ||
return text; | return text; | ||
} | } | ||
string | |||
string cleanup(float value) | |||
{ | { | ||
integer i; | string str = (string)value; | ||
integer | if(value >= 10.0) | ||
string url = "http://chart.apis.google.com/chart" | return llGetSubString(str, 0, -8); | ||
integer i = -1; | |||
while(llGetSubString(str, i, i) == "0") --i; | |||
if(llGetSubString(str, i, i) == ".") --i; | |||
return llGetSubString(str, 0, i); | |||
} | |||
string chartUrl(list values, list captions, integer yDivisions) | |||
{ | |||
integer min = llFloor(llListStatistics(LIST_STAT_MIN, values)); | |||
integer max = llCeil(llListStatistics(LIST_STAT_MAX, values)); | |||
string url = "http://chart.apis.google.com/chart" | |||
+ "?chs=200x125" | |||
+ "&chd=s:" + simpleEncode(values, min, max) | |||
+ "&cht=lc" | |||
+ "&chxt=x,y" | |||
+ "&chxl=0:"; | |||
integer i = ~llGetListLength(captions); | |||
while(++i) | |||
url += "|" + llEscapeURL(llList2String(captions, i)); | url += "|" + llEscapeURL(llList2String(captions, i)); | ||
url += "|1: | url += "|1:"; | ||
++yDivisions; | |||
float range = max - min; | |||
for(i = 0; i <= yDivisions; ++i) | |||
url += "|" + cleanup(((i * range) / yDivisions) + min); | |||
return url; | return url; | ||
} | } | ||
Line 51: | Line 58: | ||
state_entry() | state_entry() | ||
{ | { | ||
llSay(0, chartUrl([8,8,3,2,1,5,3,2,2,3,1,4,6,3,4,7,5,6,5,5,4,5,5,6,4], ["4AM", "4PM", "4AM"])); | llSay(0, chartUrl([8,8,3,2,1,5,3,2,2,3,1,4,6,3,4,7,5,6,5,5,4,5,5,6,4], ["4AM", "4PM", "4AM"], 0)); | ||
} | } | ||
touch_start(integer total_number) | touch_start(integer total_number) | ||
{ | { | ||
llSay(0, chartUrl([8,8,3,2,1,5,3,2,2,3,1,4,6,3,4,7,5,6,5,5,4,5,5,6,4], ["4AM", "4PM", "4AM"])); | llSay(0, chartUrl([8,8,3,2,1,5,3,2,2,3,1,4,6,3,4,7,5,6,5,5,4,5,5,6,4], ["4AM", "4PM", "4AM"], 0)); | ||
} | } | ||
} | }</lsl> | ||
</lsl> | |||
{{LSLC|Library|Google Charts}} | {{LSLC|Library|Google Charts}} | ||
{{LSLC|Examples|Google Charts}} | {{LSLC|Examples|Google Charts}} |
Revision as of 02:55, 1 January 2008
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
This script allows you to take an existing list of values and represent it as a chart using Google's Chart API. The example here takes a list of visitors per hour and represents it as a bar chart. The simpleEncoding method provided by Google has been converted to LSL script.
<lsl>string simpleEncode(list values, float min, float max) {
string text = ""; float range = 244 / (min - max);//4 * 61 integer index = llGetListLength(values); while(index) { integer type = llGetListEntryType(values, --index); if(type == TYPE_FLOAT || type == TYPE_INTEGER) text = llGetSubString(llIntegerToBase64((integer)(range * (min - llList2Float(values, index)))), 4, 4) + text; else text = "_" + text; } return text;
}
string cleanup(float value) {
string str = (string)value; if(value >= 10.0) return llGetSubString(str, 0, -8); integer i = -1; while(llGetSubString(str, i, i) == "0") --i; if(llGetSubString(str, i, i) == ".") --i; return llGetSubString(str, 0, i);
}
string chartUrl(list values, list captions, integer yDivisions) {
integer min = llFloor(llListStatistics(LIST_STAT_MIN, values)); integer max = llCeil(llListStatistics(LIST_STAT_MAX, values)); string url = "http://chart.apis.google.com/chart" + "?chs=200x125" + "&chd=s:" + simpleEncode(values, min, max) + "&cht=lc" + "&chxt=x,y" + "&chxl=0:"; integer i = ~llGetListLength(captions); while(++i) url += "|" + llEscapeURL(llList2String(captions, i)); url += "|1:"; ++yDivisions; float range = max - min; for(i = 0; i <= yDivisions; ++i) url += "|" + cleanup(((i * range) / yDivisions) + min); return url;
}
default {
state_entry() { llSay(0, chartUrl([8,8,3,2,1,5,3,2,2,3,1,4,6,3,4,7,5,6,5,5,4,5,5,6,4], ["4AM", "4PM", "4AM"], 0)); }
touch_start(integer total_number) { llSay(0, chartUrl([8,8,3,2,1,5,3,2,2,3,1,4,6,3,4,7,5,6,5,5,4,5,5,6,4], ["4AM", "4PM", "4AM"], 0)); }
}</lsl>