[google_chart]

Description

Link: [google_chart]
Author: Randy Phillips
Category: Utility
Version: 8.5.x
License: Public Domain
Posted: Oct. 17, 2008
Updated: Oct. 18, 2008
More by this author...

The purpose of this tag is to access the most commonly used charts from Google's Chart API. It generates a URL request to Google with specified parameters and returns a chart of your data as a PNG file.

Refer to Google's Chart API for chart type codes, marker type codes, etc.
Docs @ http://code.google.com/apis/chart/

Note: This ctag does not incorporate all the chart types and features available in the API. I have only accessed the most common types of charts, i.e., bar, pie, line, etc.  I thought adding the entire API would have made the tag unduly complex. I may do an advanced chart tag later.

Parameters

-type string, required Specify the type of chart (see API docs)
-data map, required Specify a map of data name/data value(s)
-size string, optional PNG image size
-title string, optional Gives your chart a title header
-legend boolean, optional If true a legend displays
-legendPos string, optional Specify where The legend will display (see API docs for options)
-colors string, optional Add an array of one or more color hex codes to data (without # sign)
-grid array, optional Add an array of x/y values for chart grid lines
-axis map, optional Adds labels to the top, bottom, left and/or right axis of the chart (see API docs for axis codes)
-marker string, optional Adds markers to data point such as squares or circles (see API docs for marker codes)
-markerColor string, optional Color your markers with a color hex code value
-markerSize string, optional Specify a point size for your marker

Sample Usage

google_chart(
	-title='Vertical Bar Chart', 
	-size='475x250', 
	-type='bvg', 
	-legend=true, 
	-legendPos='l', 
	-data=map('Exp' = '40,30,20', 'Income' = '40,60,59.5', 'Debt' = '20,10,40.5'),
	-axis=map('x' = 'Jan,Feb,Mar', 'y' = '0,25,50,75,100', 't' = 'A,B,C', 'r' = '0,50,100'),
	-colors=array('666666', 'cccccc', 'cc0000'),
	-grid=array(25,25)
	);

google_chart(
	-title='3D Pie Chart', 
	-size='475x250', 
	-type='p3', 
	-legend=true, 
	-legendPos='r', 
	-data=map('Exp' = '40', 'Income' = '40', 'Debt' = '20'),
	-colors=array('cc0000')
	);
		
google_chart(	
	-title='Google Meter',
	-size='475x250', 
	-type='gom',  
	-data=map('Debt-O-Meter' = '45'),
	-colors=array('ffffff', 'cc0000')
	);
	
google_chart(
	-title='Line Chart', 
	-size='475x250', 
	-type='lc', 
	-legend=true, 
	-legendPos='l', 
	-data=map('Exp' = '40,30,20', 'Income' = '40,60,59.5', 'Debt' = '20,10,40.5'),
	-axis=map('x' = 'Jan,Feb,Mar', 'r' = '0,25,50,75,100'),
	-colors=array('666666', 'cccccc', 'cc0000'),
	-marker='d',
	-markerColor='cc0000',
	-markerSize='12',
	-grid=array(0,25)
	);


google_chart(
	-title='Horizontal Stacked Bar Chart', 
	-size='500x175', 
	-type='bhs', 
	-legend=true, 
	-legendPos='t', 
	-data=map('Exp' = '40,30,20', 'Income' = '40,60,59.5', 'Debt' = '20,10,40.5'),
	-axis=map('y' = 'Jan,Feb,Mar', 'x' = '0,25,50,75,100'),
	-colors=array('666666', 'cccccc', 'cc0000'),
	-grid=array(25,25)
	);
	
google_chart(
	-title='Basic Pie Chart', 
	-size='475x250', 
	-type='p', 
	-legend=true, 
	-legendPos='r', 
	-data=map('Exp' = '40', 'Income' = '40', 'Debt' = '20'),
	-colors=array('666666', 'cccccc', 'cc0000'),
	);
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
Author: Randy Phillips
Date: 10/15/2008
Purpose: To access Google's Chart API.
Refer to Google's Chart API for chart type codes, marker type codes, etc.
Docs @ http://code.google.com/apis/chart/
Note: This ctag does not incorporate all the chart types and features available in the API
I have only accessed the most common types of charts, bar, pie, line, etc. 
I felt that adding the entire API would have made the tag unduly complex for charts that may rarely be used.

Examples
---------------------------------------------------------------------------------------
google_chart(
	-title='Vertical Bar Chart', 
	-size='475x250', 
	-type='bvg', 
	-legend=true, 
	-legendPos='l', 
	-data=map('Exp' = '40,30,20', 'Income' = '40,60,59.5', 'Debt' = '20,10,40.5'),
	-axis=map('x' = 'Jan,Feb,Mar', 'y' = '0,25,50,75,100', 't' = 'A,B,C', 'r' = '0,50,100'),
	-colors=array('666666', 'cccccc', 'cc0000'),
	-grid=array(25,25)
	);

google_chart(
	-title='3D Pie Chart', 
	-size='475x250', 
	-type='p3', 
	-legend=true, 
	-legendPos='r', 
	-data=map('Exp' = '40', 'Income' = '40', 'Debt' = '20'),
	-colors=array('cc0000')
	);
		
google_chart(	
	-title='Google Meter',
	-size='475x250', 
	-type='gom',  
	-data=map('Debt-O-Meter' = '45'),
	-colors=array('ffffff', 'cc0000')
	);
	
google_chart(
	-title='Line Chart', 
	-size='475x250', 
	-type='lc', 
	-legend=true, 
	-legendPos='l', 
	-data=map('Exp' = '40,30,20', 'Income' = '40,60,59.5', 'Debt' = '20,10,40.5'),
	-axis=map('x' = 'Jan,Feb,Mar', 'r' = '0,25,50,75,100'),
	-colors=array('666666', 'cccccc', 'cc0000'),
	-marker='d',
	-markerColor='cc0000',
	-markerSize='12',
	-grid=array(0,25)
	);


google_chart(
	-title='Horizontal Stacked Bar Chart', 
	-size='500x175', 
	-type='bhs', 
	-legend=true, 
	-legendPos='t', 
	-data=map('Exp' = '40,30,20', 'Income' = '40,60,59.5', 'Debt' = '20,10,40.5'),
	-axis=map('y' = 'Jan,Feb,Mar', 'x' = '0,25,50,75,100'),
	-colors=array('666666', 'cccccc', 'cc0000'),
	-grid=array(25,25)
	);
	
google_chart(
	-title='Basic Pie Chart', 
	-size='475x250', 
	-type='p', 
	-legend=true, 
	-legendPos='r', 
	-data=map('Exp' = '40', 'Income' = '40', 'Debt' = '20'),
	-colors=array('666666', 'cccccc', 'cc0000'),
	);
	
*/

define_tag( 
        'chart', -namespace='google_',
        -req='type', 
        -req='data', -type='map', 
        -opt='size',
        -opt='title',
        -opt='legend', -type='boolean', 
        -opt='legendPos',
        -opt='colors', -type='array',
        -opt='grid', -type='array', 
        -opt='axis', -type='map', 
        -opt='marker',
        -opt='markerColor',
        -opt='markerSize',
        -encodenone 
    ); 
    
    !local_defined('size') ? local('size') = '250x100';
    !local_defined('legend') ? local('legend') = array;
    !local_defined('colors') ? local('colors') = array;
    !local_defined('grid') ? local('grid') = array;
    !local_defined('title') ? local('title') = string;
    !local_defined('legend') ? local('legend') = false;
    !local_defined('legendPos') ? local('legendPos') = string;
    !local_defined('axis') ? local('axis') = map;
    !local_defined('marker') ? local('marker') = string;
    !local_defined('markerColor') ? local('markerColor') = 'cc0000';
    !local_defined('markerSize') ? local('markerSize') = '8';
    
    local('imgURL') = '<img src="http://chart.apis.google.com/chart?chs=' + #size;
  
    // add labels if axis labels not specified    
    if(#axis->size == 0);
    	#imgURL += '&chl=';
    
    	iterate(#data, local('label'));
    		#imgURL +=  #label->first + '|';
    	/iterate;
    
    	#imgURL->removetrailing('|');
    /if;
    
    // add required data points
     #imgURL += '&chd=t:';
    
    iterate(#data, local('point'));
    #point->second >> ',' ? local('delimiter') = '|' | local('delimiter') = ',';
    	#imgURL +=  #point->second + #delimiter;
    /iterate;
    
    #imgURL->removetrailing(#delimiter);
    
    
    // place data markers if specified 
    if(#marker);
    
    #imgURL += '&chm=';
    
    local('dataIdx' = 0);
    iterate(#data, local('point')); 
    	local('dataPoint' = 0);
    	local('coords') = #point->second->split(',');
    	iterate(#coords, local('c'));
    		#imgURL += #marker + ',' + #markerColor + ',' + #dataIdx + ',' + #dataPoint + ',' + #markerSize + '|';
    		#dataPoint++;
    	/iterate;
	#dataIdx++;
    /iterate;
   	 
    /if;
    
     #imgURL->removetrailing('|');
    
	// pick required chart type 
    #imgURL += '&cht=' + #type;
   
   // add optional chart title
    #title ? #imgURL += '&chtt=' + #title;
    
    #legend->size > 0 ? #imgURL += '&chdl=';
    
     iterate(#legend, local('str'));
    	#imgURL +=  #str + '|';
    /iterate;
    
    #imgURL->removetrailing('|');
       
    // add optional legend
   if(#legend);
    
    	#imgURL += '&chdl=';
    
    	iterate(#data, local('legend'));
    		#imgURL +=  #legend->first + '|';
    	/iterate;
    
    	#imgURL->removetrailing('|');
    
    /if;
    
    // add legend position
    #legendPos ? #imgURL += '&chdlp=' + #legendPos;
    
    // add optional colors
    #colors->size > 0 ? #imgURL += '&chco=';
    
     iterate(#colors, local('hex'));
    	#imgURL +=  #hex + ',';
    /iterate;
    
    #imgURL->removetrailing(',');
    
    // add axis types and lables
    #axis->size > 0 ? #imgURL += '&chxt=';
    
     iterate(#axis, local('axisType'));
    	#imgURL +=  #axisType->first + ',';
    /iterate;
    
    #imgURL->removetrailing(',');
    
    // add axis lables
    #axis->size > 0 ? #imgURL += '&chxl=';
    local('axisCount' = 0);    
     iterate(#axis, local('str'));   
     	#imgURL += #axisCount + ':|';     
     		local('xlabelArray') = #str->second->split(',');
     		iterate(#xlabelArray, local('axisLabel'));
     			 #imgURL += #axisLabel + '|';
     		/iterate;     
     	#axisCount++;
    /iterate;
    
    #imgURL->removetrailing('|');
    
        
    // add grid lines
    #grid->size > 0 ? #imgURL += '&chg=';
    
     iterate(#grid, local('lines'));
    	#imgURL +=  #lines + ',';
    /iterate;
    
     #imgURL->removetrailing(',');
    
    
    #imgURL += '" alt="' + #title + '" border="0" />';
    
     return(#imgURL); 
     
/define_tag;

 

Comments

none

Email:


Password:



Newest

Most Popular