Difference between revisions of "Google Charts"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
{{LSL Header}} | |||
This script allows you to take an existing list of values and represent it as a chart using [http://code.google.com/apis/chart/|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. | |||
[[Image:http://chart.apis.google.com/chart?chs=200x125&chd=s:99WPHmWPPWHetWe1mtmmemmte&cht=lc&chxt=x,y&chxl=0:|4AM|4PM|4AM|1:||8]] | |||
<lsl> | <lsl> | ||
string simpleEncoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | string simpleEncoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
string simpleEncode(list values) | string simpleEncode(list values) | ||
Line 39: | Line 46: | ||
return url; | 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"])); | |||
} | |||
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"])); | |||
} | |||
} | |||
</lsl> | </lsl> | ||
{{LSLC|Library|Google Charts}} | {{LSLC|Library|Google Charts}} | ||
{{LSLC|Examples|Google Charts}} | {{LSLC|Examples|Google Charts}} |
Revision as of 18:40, 31 December 2007
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 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 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;
}
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"])); }
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"])); }
}
</lsl>