googlecharts 1.3.6 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,570 @@
1
+ h1. Googlecharts
2
+
3
+ h2. → 'Sexy Charts using Google API & Ruby'
4
+
5
+
6
+ h2. What
7
+
8
+ A nice and simple wrapper for "Google Chart API":http://code.google.com/apis/chart/
9
+ (Fully tested using RSpec, check the specs for more usage examples)
10
+
11
+ h2. Installing
12
+
13
+ This project is now hosted at "GitHub":http://github.com
14
+ If you never added "GitHub":http://github.com as a gem source, you will need to do the following:
15
+ <pre syntax="ruby">$ gem sources -a http://gems.github.com/</pre> (you only need to do this once)
16
+
17
+ <pre syntax="ruby">$ sudo gem install mattetti-googlecharts</pre>
18
+
19
+ or <pre syntax="ruby">$ sudo gem install googlecharts</pre>
20
+
21
+ h2. The basics
22
+
23
+ This gem supports the following types of charts:
24
+
25
+ !http://chart.apis.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld&chxt=x,y&chxl=0:|Mar|Apr|May|June|July|1:||50+Kb(Line)! Gchart.line()
26
+
27
+ !http://chart.apis.google.com/chart?cht=lxy&chs=200x125&chd=t:0,30,60,70,90,95,100|20,30,40,50,60,70,80|10,30,40,45,52|100,90,40,20,10|-1|5,33,50,55,7&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,5|s,0000ff,1,-1,5|s,00aa00,2,-1,5(line_xy)! Gchart.line_xy()
28
+
29
+ !http://chart.apis.google.com/chart?cht=s&chd=s:984sttvuvkQIBLKNCAIi,DEJPgq0uov17zwopQODS,AFLPTXaflptx159gsDrn&chxt=x,y&chxl=0:|0|2|3|4|5|6|7|8|9|10|1:|0|25|50|75|100&chs=200x125(scatter)! Gchart.scatter()
30
+
31
+ !http://chart.apis.google.com/chart?cht=bvg&chs=200x125&chd=s:hello,world&chco=cc0000,00aa00(bar)! Gchart.bar()
32
+
33
+ !http://chart.apis.google.com/chart?cht=v&chs=200x100&chd=t:100,80,60,30,30,30,10(venn)! Gchart.venn()
34
+
35
+ !http://chart.apis.google.com/chart?cht=p&chd=s:world5&chs=200x125&chl=A|B|C|D|E|Fe(pie)! Gchart.pie()
36
+
37
+ !http://chart.apis.google.com/chart?cht=p3&chd=s:Uf9a&chs=200x100&chl=A|B|C|D(pie_3d)! Gchart.pie_3d()
38
+
39
+ !http://chart.apis.google.com/chart?chs=100x20&cht=ls&chco=0077CC&chm=B,E6F2FA,0,0,0&chls=1,0,0&chd=t:27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25(sparkline)!Gchart.sparkline()
40
+
41
+ !http://chart.apis.google.com/chart?chs=225x125&cht=gom&chd=t:70&chl=Flavor(google-o-meter)! Gchart.meter()
42
+
43
+ h2. Demonstration of usage
44
+
45
+ install:
46
+
47
+ <code>sudo gem install mattetti-googlecharts</code>
48
+
49
+ or use rubyforge:
50
+
51
+ <code>sudo gem install googlecharts</code>
52
+
53
+ require:
54
+ <pre syntax="ruby">require 'gchart'</pre>
55
+
56
+ <pre syntax="ruby">
57
+ Gchart.line(:size => '200x300',
58
+ :title => "example title",
59
+ :bg => 'efefef',
60
+ :legend => ['first data set label', 'second data set label'],
61
+ :data => [10, 30, 120, 45, 72])</pre>
62
+
63
+ ---
64
+
65
+ *simple line chart*
66
+ <pre syntax="ruby">
67
+ Gchart.line(:data => [0, 40, 10, 70, 20])
68
+ </pre>
69
+
70
+ Generate the following url: http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc
71
+
72
+ Inserted in an image tag, it will look like that:
73
+
74
+ !http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc(simple line chart)!
75
+
76
+ *multiple line charts*
77
+ <pre syntax="ruby">
78
+ Gchart.line(:data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]])
79
+ </pre>
80
+
81
+ !http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:AeH1P,fH9m(multiple lines chart)!
82
+
83
+ *set line colors*
84
+
85
+ <pre syntax="ruby">
86
+ Gchart.line(:data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :line_colors => "FF0000,00FF00")
87
+ </pre>
88
+
89
+ !http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:AeH1P,fH9m&chco=FF0000,00FF00(line colors)!
90
+
91
+ "more info about color settings":http://code.google.com/apis/chart/#chart_colors
92
+
93
+ *sparkline chart*
94
+
95
+ <pre syntax="ruby">
96
+ data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25]
97
+ Gchart.sparkline(:data => data, :size => '120x40', :line_colors => '0077CC')
98
+ </pre>
99
+
100
+ !http://chart.apis.google.com/chart?chd=s:QPPPPQ9SPVPPXPSPPPPPPPRPP9RQSPQQRPQPPPPPVUUPPPVPPWUUWWXPPPP&chco=0077CC&chs=120x40&cht=ls(sparline)!
101
+
102
+ A sparkline chart has exactly the same parameters as a line chart. The only difference is that the axes lines are not drawn for sparklines by default.
103
+
104
+ *bar chart*
105
+
106
+ <pre syntax="ruby">
107
+ Gchart.bar(:data => [300, 100, 30, 200])
108
+ </pre>
109
+ !http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo(bars)!
110
+
111
+ *set the bar chart orientation*
112
+
113
+ <pre syntax="ruby">
114
+ Gchart.bar(:data => [300, 100, 30, 200], :orientation => 'horizontal')
115
+ </pre>
116
+ !http://chart.apis.google.com/chart?cht=bhs&chs=300x200&chd=s:9UGo(bars)!
117
+
118
+ *multiple bars chart*
119
+
120
+ <pre syntax="ruby">
121
+ Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]])
122
+ </pre>
123
+
124
+ !http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo,Uo9C(stacked multiple bars)!
125
+
126
+ The problem is that by default the bars are stacked, so we need to set the colors:
127
+
128
+ <pre syntax="ruby">
129
+ Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], :bar_colors => 'FF0000,00FF00')
130
+ </pre>
131
+
132
+ If you prefer you can use this other syntax:
133
+
134
+ <pre syntax="ruby">
135
+ Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], :bar_colors => ['FF0000', '00FF00'])
136
+ </pre>
137
+
138
+ !http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00(colors)!
139
+
140
+ The problem now, is that we can't see the first value of the second dataset since it's lower than the first value of the first dataset. Let's unstack the bars:
141
+
142
+ <pre syntax="ruby">
143
+ Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]],
144
+ :bar_colors => 'FF0000,00FF00',
145
+ :stacked => false )
146
+ </pre>
147
+
148
+ !http://chart.apis.google.com/chart?cht=bvg&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00(grouped bars)!
149
+
150
+ *bar chart width and spacing*
151
+
152
+ A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash.
153
+
154
+ The Google API sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order:
155
+
156
+ <pre syntax="ruby">
157
+ Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6
158
+ Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12
159
+ Gchart.bar(:data => @data, :bar_width_and_spacing => [25,6]) # width of 25, spacing of 6
160
+ Gchart.bar(:data => @data, :bar_width_and_spacing => 25) # width of 25
161
+ </pre>
162
+
163
+ The hash lets you set these values directly, with the Google default values set for any options you don't include:
164
+
165
+ <pre syntax="ruby">
166
+ Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19})
167
+ Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12})
168
+ </pre>
169
+
170
+
171
+ *pie chart*
172
+
173
+ <pre syntax="ruby">
174
+ Gchart.pie(:data => [20, 35, 45])
175
+ </pre>
176
+ !http://chart.apis.google.com/chart?cht=p&chs=300x200&chd=s:bv9(Pie Chart)!
177
+
178
+ *3D pie chart*
179
+
180
+ <pre syntax="ruby">
181
+ Gchart.pie_3d(:data => [20, 35, 45])
182
+ </pre>
183
+ !http://chart.apis.google.com/chart?cht=p3&chs=300x200&chd=s:bv9(Pie Chart)!
184
+
185
+ *venn diagram*
186
+
187
+ "Google documentation":http://code.google.com/apis/chart/#venn
188
+
189
+ Data set:
190
+ * the first three values specify the relative sizes of three circles, A, B, and C
191
+ * the fourth value specifies the area of A intersecting B
192
+ * the fifth value specifies the area of B intersecting C
193
+ * the sixth value specifies the area of C intersecting A
194
+ * the seventh value specifies the area of A intersecting B intersecting C
195
+
196
+ <pre syntax="ruby">
197
+ Gchart.venn(:data => [100, 80, 60, 30, 30, 30, 10])
198
+ </pre>
199
+ !http://chart.apis.google.com/chart?cht=v&chs=300x200&chd=s:9wkSSSG(Venn)!
200
+
201
+ *scatter plot*
202
+
203
+ "Google Documentation":http://code.google.com/apis/chart/#scatter_plot
204
+
205
+ Supply two data sets, the first data set specifies x coordinates, the second set specifies y coordinates, the third set the data point size.
206
+
207
+ <pre syntax="ruby">
208
+ Gchart.scatter(:data => [[1, 2, 3, 4, 5], [1, 2, 3, 4 ,5], [5, 4, 3, 2, 1]])
209
+ </pre>
210
+
211
+ !http://chart.apis.google.com/chart?cht=s&chs=300x200&chd=s:MYkw9,MYkw9,9wkYM(scatter)!
212
+
213
+ *google-o-meter*
214
+
215
+ "Google Documentation":http://code.google.com/apis/chart/#gom
216
+
217
+ Supply a single label that will be what the arrow points to. It only supports a solid fill for the background.
218
+
219
+ <pre syntax="ruby">
220
+ Gchart.meter(:data => [70], :label => ['Flavor'])
221
+ </pre>
222
+
223
+
224
+ *Chart themes*
225
+
226
+ Googlecharts comes with 4 themes: keynote, thirty7signals, pastel and greyscale. (ganked from "Gruff": http://github.com/topfunky/gruff/tree/master )
227
+
228
+ <pre syntax="ruby">
229
+ Gchart.line(
230
+ :theme => :keynote,
231
+ :data => [[0,40,10,70,20],[41,10,80,50,40],[20,60,30,60,80],[5,23,35,10,56],[80,90,5,30,60]],
232
+ :title => 'keynote'
233
+ )
234
+ </pre>
235
+
236
+ * keynote
237
+
238
+ !http://chart.apis.google.com/chart?chtt=keynote&chco=6886B4,FDD84E,72AE6E,D1695E,8A6EAF,EFAA43&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=c,s,FFFFFF|bg,s,000000!
239
+
240
+ * thirty7signals
241
+
242
+ !http://chart.apis.google.com/chart?chtt=thirty7signals&chco=FFF804,336699,339933,ff0000,cc99cc,cf5910&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=bg,s,FFFFFF!
243
+
244
+ * pastel
245
+
246
+ !http://chart.apis.google.com/chart?chtt=pastel&chco=a9dada,aedaa9,daaea9,dadaa9,a9a9da&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo!
247
+
248
+ * greyscale
249
+
250
+ !http://chart.apis.google.com/chart?chtt=greyscale&chco=282828,383838,686868,989898,c8c8c8,e8e8e8&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo!
251
+
252
+
253
+ You can also use your own theme. Create a yml file using the same format as the themes located in lib/themes.yml
254
+
255
+ Load your theme(s):
256
+
257
+ <pre syntax="ruby">
258
+ Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml")
259
+ </pre>
260
+
261
+ And use the standard method signature to use your own theme:
262
+
263
+ <pre syntax="ruby">
264
+ Gchart.line(:theme => :custom_theme, :data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :title => 'greyscale')
265
+ </pre>
266
+
267
+
268
+ ---
269
+
270
+ *set a chart title*
271
+
272
+ <pre syntax="ruby">
273
+ Gchart.bar(:title => "Recent Chart Sexyness", :data => [15, 30, 10, 20, 100, 20, 40, 100])
274
+ </pre>
275
+
276
+ !http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness(chart title)!
277
+
278
+ *set the title size*
279
+
280
+ <pre syntax="ruby">
281
+ Gchart.bar(:title => "Recent Chart Sexyness", :title_size => 20, :data => [15, 30, 10, 20, 100, 20, 40, 100])
282
+ </pre>
283
+
284
+ !http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness&chts=454545,20(title size)!
285
+
286
+ *set the title color*
287
+
288
+ <pre syntax="ruby">
289
+ Gchart.bar(:title => "Recent Chart Sexyness", :title_color => 'FF0000', :data => [15, 30, 10, 20, 100, 20, 40, 100])
290
+ </pre>
291
+
292
+ !http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness&chts=FF0000(Title color)!
293
+
294
+ *set the chart's size*
295
+
296
+ <pre syntax="ruby">
297
+ Gchart.bar(:title => "Recent Chart Sexyness",
298
+ :data => [15, 30, 10, 20, 100, 20, 40, 100],
299
+ :size => '600x400')
300
+ </pre>
301
+
302
+ !http://chart.apis.google.com/chart?cht=bvs&chs=600x400&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness(size)!
303
+
304
+ *set the image background color*
305
+
306
+ <pre syntax="ruby">
307
+ Gchart.bar(:title => "Matt's Mojo",
308
+ :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80],
309
+ :background => 'FF9994')
310
+ </pre>
311
+
312
+ !http://chart.apis.google.com/chart?chf=bg,s,FF9994&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chtt=Matt's+Mojo(Background)!
313
+
314
+ *set the chart background color*
315
+
316
+ <pre syntax="ruby">
317
+ Gchart.bar(:title => "Matt's Mojo",
318
+ :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80],
319
+ :background => 'FF9994', :chart_background => '000000')
320
+ </pre>
321
+
322
+ !http://chart.apis.google.com/chart?chf=c,s,000000|bg,s,FF9994&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chtt=Matt's+Mojo(chart background)!
323
+
324
+ *Set bar/line colors*
325
+
326
+ <pre syntax="ruby">
327
+ Gchart.bar(:title => "Matt's Mojo",
328
+ :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80],
329
+ :bar_colors => '76A4FB',
330
+ :background => 'EEEEEE', :chart_background => 'CCCCCC')
331
+ </pre>
332
+
333
+ !http://chart.apis.google.com/chart?chf=c,s,CCCCCC|bg,s,EEEEEE&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chco=76A4FB&chtt=Matt's+Mojo(bar colors)!
334
+
335
+ <pre syntax="ruby">
336
+ Gchart.line(:title => "Matt's Mojo",
337
+ :data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80],
338
+ :line_colors => '76A4FB')
339
+ </pre>
340
+
341
+ !http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:JSGM9MY929w&chco=76A4FB&chtt=Matt's+Mojo(line colors)!
342
+
343
+ *legend / labels*
344
+
345
+ <pre syntax="ruby">
346
+ Gchart.bar(:title => "Matt vs Rob",
347
+ :data => [[300, 100, 30, 200], [100, 200, 300, 10]],
348
+ :bar_colors => 'FF0000,00FF00',
349
+ :stacked => false, :size => '400x200',
350
+ :legend => ["Matt's Mojo", "Rob's Mojo"] )
351
+ </pre>
352
+ !http://chart.apis.google.com/chart?cht=bvg&chdl=Matt's+Mojo|Rob's+Mojo&chs=400x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00&chtt=Matt+vs+Rob(legend)!
353
+
354
+ <pre syntax="ruby">
355
+ Gchart.line(:title => "Matt vs Rob",
356
+ :data => [[300, 100, 30, 200], [100, 200, 300, 10]],
357
+ :bar_colors => ['FF0000','00FF00'],
358
+ :stacked => false, :size => '400x200',
359
+ :legend => ["Matt's Mojo", "Rob's Mojo"] )
360
+ </pre>
361
+ !http://chart.apis.google.com/chart?cht=lc&chdl=Matt's+Mojo|Rob's+Mojo&chs=400x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00&chtt=Matt+vs+Rob(line legend)!
362
+
363
+
364
+ <pre syntax="ruby">
365
+ Gchart.pie_3d(:title => 'ruby_fu', :size => '400x200',
366
+ :data => [10, 45, 45], :labels => ["DHH", "Rob", "Matt"] )
367
+ </pre>
368
+
369
+ !http://chart.apis.google.com/chart?cht=p3&chl=DHH|Rob|Matt&chs=400x200&chd=s:N99&chtt=ruby_fu(labels)!
370
+
371
+ *Display axis labels*
372
+
373
+ <pre syntax="ruby">
374
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,y,r')
375
+ </pre>
376
+
377
+ or you can use the other syntax:
378
+
379
+ <pre syntax="ruby">
380
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => ['x','y','r'])
381
+ </pre>
382
+
383
+ !http://chart.apis.google.com/chart?cht=lc&chs=300x200&chxt=x,y,r&chd=s:9UGoUo9C(axis with labels)!
384
+
385
+ <pre syntax="ruby">
386
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x',
387
+ :axis_labels => ['Jan|July|Jan|July|Jan'])
388
+ </pre>
389
+
390
+ or you can use the other syntax:
391
+
392
+ <pre syntax="ruby">
393
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x',
394
+ :axis_labels => ['Jan','July','Jan','July','Jan'])
395
+ </pre>
396
+
397
+ !http://chart.apis.google.com/chart?cht=lc&chxl=0:|Jan|July|Jan|July|Jan&chs=300x200&chxt=x&chd=s:9UGoUo9C(x labels)!
398
+
399
+ *multiple axis labels*
400
+
401
+ <pre syntax="ruby">
402
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,r',
403
+ :axis_labels => ['Jan|July|Jan|July|Jan', '2005|2006|2007'])
404
+ </pre>
405
+
406
+ or
407
+
408
+ <pre syntax="ruby">
409
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,r',
410
+ :axis_labels => [['Jan','July','Jan','July','Jan'], ['2005','2006','2007']])
411
+ </pre>
412
+
413
+ !http://chart.apis.google.com/chart?cht=lc&chxl=0:|Jan|July|Jan|July|Jan|1:|2005|2006|2007&chs=300x200&chxt=x,r&chd=s:9UGoUo9C(multiple axis labels)!
414
+
415
+ (This syntax will probably be improved in the future)
416
+
417
+ *custom params*
418
+
419
+ I certainly didn't cover the entire API, if you want to add your own params:
420
+
421
+ <pre syntax="ruby">
422
+ Gchart.line(:custom => 'chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&chls=3,6,3|1,1,0')
423
+ </pre>
424
+
425
+ !http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&chls=3,6,3|1,1,0(Custom)!
426
+
427
+ ---
428
+
429
+ *Save the chart as a file*
430
+
431
+ You might prefer to save the chart instead of using the url, not a problem:
432
+
433
+ <pre syntax="ruby">
434
+ Gchart.line(:data => [0, 26], :format => 'file')
435
+ </pre>
436
+
437
+ You might want to specify the path and/or the filename used to save your chart:
438
+
439
+ <pre syntax="ruby">
440
+ Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_filename.png')
441
+ </pre>
442
+
443
+ *Insert as an image tag*
444
+
445
+ Because, I'm lazy, you can generate a full image tag, with support for standard html options.
446
+
447
+ <pre syntax="ruby">
448
+ Gchart.line(:data => [0, 26], :format => 'image_tag')
449
+ </pre>
450
+
451
+ <pre syntax="ruby">
452
+ <img src="http://chart.apis.google.com/chart?chs=300x200&amp;chd=s:A9&amp;cht=lc" width="300" height="200" alt="Google Chart" />
453
+ </pre>
454
+
455
+ Here are a few more examples:
456
+
457
+ <pre syntax="ruby">
458
+ Gchart.line(:data => [0, 26], :format => 'image_tag')
459
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :id => "sexy")
460
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :class => "chart")
461
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => "Sexy Chart")
462
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :title => "Sexy Chart")
463
+ </pre>
464
+
465
+ Image dimensions will be automatically set based on your chart's size.
466
+
467
+ ---
468
+
469
+ *Encoding*
470
+
471
+ Google Chart API offers "3 types of data encoding":http://code.google.com/apis/chart/#chart_data
472
+
473
+ * simple
474
+ * text
475
+ * extended
476
+
477
+ By default this library uses the simple encoding, if you need a different type of encoding, you can change it really easily:
478
+
479
+ default / simple: chd=s:9UGoUo9C
480
+ <pre syntax="ruby">
481
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10] )
482
+ </pre>
483
+
484
+ extended: chd=e:..VVGZqqVVqq..CI
485
+ <pre syntax="ruby">
486
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :encoding => 'extended' )
487
+ </pre>
488
+
489
+ text: chd=t:300,100,30,200,100,200,300,10
490
+ <pre syntax="ruby">
491
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :encoding => 'text' )
492
+ </pre>
493
+
494
+ (note that the text encoding doesn't use a max value and therefore should be under 100)
495
+
496
+ *Max value*
497
+
498
+ Simple and extended encoding support the max value option.
499
+
500
+ The max value option is a simple way of scaling your graph. The data is converted in chart value with the highest chart value being the highest point on the graph. By default, the calculation is done for you. However you can specify your own maximum or not use a maximum at all.
501
+
502
+ <pre syntax="ruby">
503
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10] )
504
+ </pre>
505
+
506
+ !http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:9UGoUo9C(Title)!
507
+
508
+ <pre syntax="ruby">
509
+ Gchart.line(:data => [300, 100, 30, 200, 100, 200, 300, 10], :max_value => 500 )
510
+ </pre>
511
+
512
+ !http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:kMDYMYkB(max 500)!
513
+
514
+ <pre syntax="ruby">
515
+ Gchart.line(:data => [100, 20, 30, 20, 10, 14, 30, 10], :max_value => false )
516
+ </pre>
517
+
518
+ !http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:_UeUKOeK(real size)!
519
+
520
+
521
+ h2. Repository
522
+
523
+ The trunk repository is <code>http://github.com/mattetti/googlecharts/</code> for anonymous access.
524
+
525
+ h2. People reported using this gem
526
+
527
+
528
+ <div>
529
+ <img src="http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png" alt="github"/><br/>
530
+ <li><a href="http://github.com">http://github.com</a></li><br/>
531
+ </div>
532
+
533
+ <div>
534
+ <img src="http://stafftool.com/images/masthead_screen.gif" alt="stafftool"/><br/>
535
+ <li><a href="http://stafftool.com/">Takeo(contributor)</a></li><br/>
536
+ </div>
537
+
538
+ <div>
539
+ <img src="http://img.skitch.com/20080627-g2pp89h7gdbh15m1rr8hx48jep.jpg" alt="graffletopia"/><br/>
540
+ <li><a href="http://graffletopia.com"> http://graffletopia.com Mokolabs(contributor)</a></li><br/>
541
+ </div>
542
+
543
+ <div>
544
+ <img src="http://img.skitch.com/20080627-kc1weqsbkmxeqhwiyriq3n6g8k.jpg" alt="gumgum"/><br/>
545
+ <li><a href="http://gumgum.com"> http://gumgum.com Mattetti(contributor)</a></li><br/>
546
+ </div>
547
+
548
+ <div>
549
+ <img src="http://img.skitch.com/20080627-n48j8pb2r7irsewfeh4yp3da12.jpg" alt="feedflix"/><br/>
550
+ <li><a href="http://feedflix.com/"> http://feedflix.com/</a></li><br/>
551
+ </div>
552
+
553
+ <div>
554
+ <li><a href="http://www.csuchico.edu/"> California State University, Chico</a></li><br/>
555
+ </div>
556
+
557
+
558
+ h2. License
559
+
560
+ This code is free to use under the terms of the MIT license.
561
+
562
+ h2. Contact
563
+
564
+ Comments are welcome. Send an email to "Matt Aimonetti":mailto:mattaimonetti@gmail.com
565
+
566
+ h3. Contributors
567
+
568
+ "David Grandinetti":http://github.com/dbgrandi
569
+ "Toby Sterrett":http://github.com/takeo
570
+ "Patrick Crowley":http://github.com/mokolabs