Monday, July 28, 2008

GCHARTS: encode (vbscript)

encode: text (0..100), simple(62), extended (4096)

Option Explicit

Sub main()
Dim s
s = _
"1492,1596,1474,1611,1589,1749,1630,1619,1632,1685,1691,1637,1703,1627,1672,1611,1710,1645,1640,1570,1599," & _
"1525,1585,1511,1615,1511,1585,1473,2390,1693,1597,1550,1606,1578,1543,1539,1570,1552,1589,1545,1620,1607," & _
"1612,1647,1476,1445,1482,1478,1463,1419,1498,1503,1520,1537,1459,1531,1501,1511,1469,1478,1476,1504,1519," & _
"1499,1435,1422,1420,1303,1367,1340,1380,1374,1342,1308,1373,1415,1426,1399,1426,1420,1347,1421,1459,1459," & _
"1438,1397,1454,1462,1518,1475,1514,1460,1510,1463,1515,1498,1510,1456,1503,1590,1543,1634,1649,2449,1774," & _
"1915,1840,1890,1744,1779,1663,1726,1756,1716,1637,1680,1674,1713,1724,1660,2013,1650,2037,2622,1886,1555," & _
"1466,1535,1452,1482,1537,1387,1412,1381,1407,1252,1671,1284,1377,1264,1266,1342,1376,1323,1108,1234,1261"
s = "100,0,0,100,100"
Debug.Print chd_t1(s)
Debug.Print chd_s1(s)
Debug.Print chd_e1(s)
End Sub

Function chd_t1(s)
'http://chart.apis.google.com/chart?chs=250x200&cht=ls&chco=0077CC&chm=B,E6F2FA,0,0,0&chls=1,0,0&chd=t:57,61,56
Dim a, i, a0, a1, b
a = Split(s, ",")
a0 = a(0)
a1 = a(0)
For i = 0 To UBound(a)
If a0 > a(i) Then a0 = a(i)
If a1 < a(i) Then a1 = a(i)
Next
ReDim b(UBound(a))
For i = 0 To UBound(a)
b(i) = Round(100# / a1 * a(i), 0) ' absolute
Next
chd_t1 = Replace(Replace(Join(b, "|"), ",", "."), "|", ",")
End Function

Function chd_s1(s)
'http://chart.apis.google.com/chart?chs=250x200&cht=ls&chco=0077CC&chm=B,E6F2FA,0,0,0&chls=1,0,0&chd=s:ililloml
Dim t, a, a0&, a1&, i
t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
a = Split(s, ",")
a0 = a(0)
a1 = a(0)
For i = 0 To UBound(a)
If a0 > a(i) Then a0 = a(i)
If a1 < a(i) Then a1 = a(i)
Next
ReDim b(UBound(a))
For i = 0 To UBound(a)
b(i) = Mid(t, Round(62 * a(i) / a1, 0) + 1, 1)
Next
chd_s1 = Join(b, ".")
End Function



Function chd_e1(s)
'http://chart.apis.google.com/chart?chs=250x200&cht=ls&chco=0077CC&chm=B,E6F2FA,0,0,0&chls=1,0,0&chd=e:jbl9i.mV
Dim t, a, a0, a1, i, x
t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-."
a = Split(s, ",")
a0 = a(0)
a1 = a(0)
For i = 0 To UBound(a)
If a0 > a(i) Then a0 = a(i)
If a1 < a(i) Then a1 = a(i)
Next
ReDim b(UBound(a))
For i = 0 To UBound(a)
x = Round(a(i) / a1 * 4096, 0)
b(i) = _
Mid(t, x \ 64 + 1, 1) & _
Mid(t, x - (x \ 64) * 64 + 1, 1)
Next
chd_e1 = Join(b, "")
End Function


No comments: