dbgrandi-googlecharts 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +33 -0
- data/License.txt +20 -0
- data/Manifest.txt +16 -0
- data/README.txt +180 -0
- data/Rakefile +32 -0
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +16 -0
- data/lib/gchart.rb +392 -0
- data/lib/gchart/aliases.rb +14 -0
- data/lib/gchart/version.rb +9 -0
- data/setup.rb +1585 -0
- data/spec/gchart_spec.rb +411 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +7 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/website/index.txt +476 -0
- metadata +74 -0
data/website/index.txt
ADDED
@@ -0,0 +1,476 @@
|
|
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
|
+
|
10
|
+
h2. Installing
|
11
|
+
|
12
|
+
This project is now hosted at "GitHub":http://github.com
|
13
|
+
If you never added "GitHub":http://github.com as a gem source, you will need to do the following:
|
14
|
+
<pre syntax="ruby">$ gem sources -a http://gems.github.com/</pre> (you only need to do this once)
|
15
|
+
|
16
|
+
<pre syntax="ruby">$ sudo gem install matta-googlecharts</pre>
|
17
|
+
|
18
|
+
or <pre syntax="ruby">$ sudo gem install googlecharts</pre>
|
19
|
+
|
20
|
+
h2. The basics
|
21
|
+
|
22
|
+
This gem supports the following types of charts:
|
23
|
+
|
24
|
+
!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()
|
25
|
+
|
26
|
+
!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()
|
27
|
+
|
28
|
+
!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()
|
29
|
+
|
30
|
+
!http://chart.apis.google.com/chart?cht=bvg&chs=200x125&chd=s:hello,world&chco=cc0000,00aa00(bar)! Gchart.bar()
|
31
|
+
|
32
|
+
!http://chart.apis.google.com/chart?cht=v&chs=200x100&chd=t:100,80,60,30,30,30,10(venn)! Gchart.venn()
|
33
|
+
|
34
|
+
!http://chart.apis.google.com/chart?cht=p&chd=s:world5&chs=200x125&chl=A|B|C|D|E|Fe(pie)! Gchart.pie()
|
35
|
+
|
36
|
+
!http://chart.apis.google.com/chart?cht=p3&chd=s:Uf9a&chs=200x100&chl=A|B|C|D(pie_3d)! Gchart.pie_3d()
|
37
|
+
|
38
|
+
!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()
|
39
|
+
|
40
|
+
!http://chart.apis.google.com/chart?chs=225x125&cht=gom&chd=t:70&chl=Flavor(google-o-meter)! Gchart.meter()
|
41
|
+
|
42
|
+
h2. Demonstration of usage
|
43
|
+
|
44
|
+
install:
|
45
|
+
|
46
|
+
<code>sudo gem install matta-googlecharts</code>
|
47
|
+
|
48
|
+
or use rubyforge:
|
49
|
+
|
50
|
+
<code>sudo gem install googlecharts</code>
|
51
|
+
|
52
|
+
require:
|
53
|
+
<pre syntax="ruby">require 'gchart'</pre>
|
54
|
+
|
55
|
+
<pre syntax="ruby">Gchart.line( :size => '200x300',
|
56
|
+
:title => "example title",
|
57
|
+
:bg => 'efefef',
|
58
|
+
:legend => ['first data set label', 'second data set label'],
|
59
|
+
:data => [10, 30, 120, 45, 72])</pre>
|
60
|
+
|
61
|
+
---
|
62
|
+
|
63
|
+
*simple line chart*
|
64
|
+
<pre syntax="ruby">
|
65
|
+
Gchart.line(:data => [0, 40, 10, 70, 20])
|
66
|
+
</pre>
|
67
|
+
|
68
|
+
Generate the following url: http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc
|
69
|
+
|
70
|
+
Inserted in an image tag, it will look like that:
|
71
|
+
|
72
|
+
!http://chart.apis.google.com/chart?chs=300x200&chd=s:AiI9R&cht=lc(simple line chart)!
|
73
|
+
|
74
|
+
*multiple line charts*
|
75
|
+
<pre syntax="ruby">
|
76
|
+
Gchart.line(:data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]])
|
77
|
+
</pre>
|
78
|
+
|
79
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:AeH1P,fH9m(multiple lines chart)!
|
80
|
+
|
81
|
+
*set line colors*
|
82
|
+
|
83
|
+
<pre syntax="ruby">
|
84
|
+
Gchart.line(:data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :line_colors => "FF0000,00FF00")
|
85
|
+
</pre>
|
86
|
+
|
87
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:AeH1P,fH9m&chco=FF0000,00FF00(line colors)!
|
88
|
+
|
89
|
+
"more info about color settings":http://code.google.com/apis/chart/#chart_colors
|
90
|
+
|
91
|
+
*sparkline chart*
|
92
|
+
|
93
|
+
<pre syntax="ruby">
|
94
|
+
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]
|
95
|
+
Gchart.sparkline(:data => data, :size => '120x40', :line_colors => '0077CC')
|
96
|
+
</pre>
|
97
|
+
|
98
|
+
!http://chart.apis.google.com/chart?chd=s:QPPPPQ9SPVPPXPSPPPPPPPRPP9RQSPQQRPQPPPPPVUUPPPVPPWUUWWXPPPP&chco=0077CC&chs=120x40&cht=ls(sparline)!
|
99
|
+
|
100
|
+
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.
|
101
|
+
|
102
|
+
*bar chart*
|
103
|
+
|
104
|
+
<pre syntax="ruby">
|
105
|
+
Gchart.bar(:data => [300, 100, 30, 200])
|
106
|
+
</pre>
|
107
|
+
!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo(bars)!
|
108
|
+
|
109
|
+
*set the bar chart orientation*
|
110
|
+
|
111
|
+
<pre syntax="ruby">
|
112
|
+
Gchart.bar(:data => [300, 100, 30, 200], :orientation => 'horizontal')
|
113
|
+
</pre>
|
114
|
+
!http://chart.apis.google.com/chart?cht=bhs&chs=300x200&chd=s:9UGo(bars)!
|
115
|
+
|
116
|
+
*multiple bars chart*
|
117
|
+
|
118
|
+
<pre syntax="ruby">
|
119
|
+
Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]])
|
120
|
+
</pre>
|
121
|
+
|
122
|
+
!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo,Uo9C(stacked multiple bars)!
|
123
|
+
|
124
|
+
The problem is that by default the bars are stacked, so we need to set the colors:
|
125
|
+
|
126
|
+
<pre syntax="ruby">
|
127
|
+
Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], :bar_colors => 'FF0000,00FF00')
|
128
|
+
</pre>
|
129
|
+
|
130
|
+
If you prefer you can use this other syntax:
|
131
|
+
|
132
|
+
<pre syntax="ruby">
|
133
|
+
Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], :bar_colors => ['FF0000', '00FF00'])
|
134
|
+
</pre>
|
135
|
+
|
136
|
+
!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00(colors)!
|
137
|
+
|
138
|
+
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:
|
139
|
+
|
140
|
+
<pre syntax="ruby">
|
141
|
+
Gchart.bar( :data => [[300, 100, 30, 200], [100, 200, 300, 10]],
|
142
|
+
:bar_colors => 'FF0000,00FF00',
|
143
|
+
:stacked => false )
|
144
|
+
</pre>
|
145
|
+
|
146
|
+
!http://chart.apis.google.com/chart?cht=bvg&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00(grouped bars)!
|
147
|
+
|
148
|
+
*bar chart width and spacing*
|
149
|
+
|
150
|
+
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.
|
151
|
+
|
152
|
+
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:
|
153
|
+
|
154
|
+
<pre syntax="ruby">
|
155
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6
|
156
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12
|
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) # width of 25
|
159
|
+
</pre>
|
160
|
+
|
161
|
+
The hash lets you set these values directly, with the Google default values set for any options you don't include:
|
162
|
+
|
163
|
+
<pre syntax="ruby">
|
164
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19})
|
165
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12})
|
166
|
+
</pre>
|
167
|
+
|
168
|
+
|
169
|
+
*pie chart*
|
170
|
+
|
171
|
+
<pre syntax="ruby">
|
172
|
+
Gchart.pie(:data => [20, 35, 45])
|
173
|
+
</pre>
|
174
|
+
!http://chart.apis.google.com/chart?cht=p&chs=300x200&chd=s:bv9(Pie Chart)!
|
175
|
+
|
176
|
+
*3D pie chart*
|
177
|
+
|
178
|
+
<pre syntax="ruby">
|
179
|
+
Gchart.pie_3d(:data => [20, 35, 45])
|
180
|
+
</pre>
|
181
|
+
!http://chart.apis.google.com/chart?cht=p3&chs=300x200&chd=s:bv9(Pie Chart)!
|
182
|
+
|
183
|
+
*venn diagram*
|
184
|
+
|
185
|
+
"Google documentation":http://code.google.com/apis/chart/#venn
|
186
|
+
|
187
|
+
Data set:
|
188
|
+
* the first three values specify the relative sizes of three circles, A, B, and C
|
189
|
+
* the fourth value specifies the area of A intersecting B
|
190
|
+
* the fifth value specifies the area of B intersecting C
|
191
|
+
* the sixth value specifies the area of C intersecting A
|
192
|
+
* the seventh value specifies the area of A intersecting B intersecting C
|
193
|
+
|
194
|
+
<pre syntax="ruby">
|
195
|
+
Gchart.venn(:data => [100, 80, 60, 30, 30, 30, 10])
|
196
|
+
</pre>
|
197
|
+
!http://chart.apis.google.com/chart?cht=v&chs=300x200&chd=s:9wkSSSG(Venn)!
|
198
|
+
|
199
|
+
*scatter plot*
|
200
|
+
|
201
|
+
"Google Documentation":http://code.google.com/apis/chart/#scatter_plot
|
202
|
+
|
203
|
+
Supply two data sets, the first data set specifies x coordinates, the second set specifies y coordinates, the third set the data point size.
|
204
|
+
|
205
|
+
<pre syntax="ruby">
|
206
|
+
Gchart.scatter(:data => [[1, 2, 3, 4, 5], [1, 2, 3, 4 ,5], [5, 4, 3, 2, 1]])
|
207
|
+
</pre>
|
208
|
+
|
209
|
+
!http://chart.apis.google.com/chart?cht=s&chs=300x200&chd=s:MYkw9,MYkw9,9wkYM(scatter)!
|
210
|
+
|
211
|
+
*google-o-meter*
|
212
|
+
|
213
|
+
"Google Documentation":http://code.google.com/apis/chart/#gom
|
214
|
+
|
215
|
+
Supply a single label that will be what the arrow points to. It only supports a solid fill for the background.
|
216
|
+
|
217
|
+
<pre syntax="ruby">
|
218
|
+
Gchart.meter(:data => [70], :label => ['Flavor'])
|
219
|
+
</pre>
|
220
|
+
|
221
|
+
---
|
222
|
+
|
223
|
+
*set a chart title*
|
224
|
+
|
225
|
+
<pre syntax="ruby">
|
226
|
+
Gchart.bar(:title => "Recent Chart Sexyness", :data => [15, 30, 10, 20, 100, 20, 40, 100])
|
227
|
+
</pre>
|
228
|
+
|
229
|
+
!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness(chart title)!
|
230
|
+
|
231
|
+
*set the title size*
|
232
|
+
|
233
|
+
<pre syntax="ruby">
|
234
|
+
Gchart.bar(:title => "Recent Chart Sexyness", :title_size => 20, :data => [15, 30, 10, 20, 100, 20, 40, 100])
|
235
|
+
</pre>
|
236
|
+
|
237
|
+
!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness&chts=454545,20(title size)!
|
238
|
+
|
239
|
+
*set the title color*
|
240
|
+
|
241
|
+
<pre syntax="ruby">
|
242
|
+
Gchart.bar(:title => "Recent Chart Sexyness", :title_color => 'FF0000', :data => [15, 30, 10, 20, 100, 20, 40, 100])
|
243
|
+
</pre>
|
244
|
+
|
245
|
+
!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness&chts=FF0000(Title color)!
|
246
|
+
|
247
|
+
*set the chart's size*
|
248
|
+
|
249
|
+
<pre syntax="ruby">
|
250
|
+
Gchart.bar( :title => "Recent Chart Sexyness",
|
251
|
+
:data => [15, 30, 10, 20, 100, 20, 40, 100],
|
252
|
+
:size => '600x400')
|
253
|
+
</pre>
|
254
|
+
|
255
|
+
!http://chart.apis.google.com/chart?cht=bvs&chs=600x400&chd=s:JSGM9MY9&chtt=Recent+Chart+Sexyness(size)!
|
256
|
+
|
257
|
+
*set the image background color*
|
258
|
+
|
259
|
+
<pre syntax="ruby">
|
260
|
+
Gchart.bar( :title => "Matt's Mojo",
|
261
|
+
:data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80],
|
262
|
+
:background => 'FF9994')
|
263
|
+
</pre>
|
264
|
+
|
265
|
+
!http://chart.apis.google.com/chart?chf=bg,s,FF9994&cht=bvs&chs=300x200&chd=s:JSGM9MY929w&chtt=Matt's+Mojo(Background)!
|
266
|
+
|
267
|
+
*set the chart background color*
|
268
|
+
|
269
|
+
<pre syntax="ruby">
|
270
|
+
Gchart.bar( :title => "Matt's Mojo",
|
271
|
+
:data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80],
|
272
|
+
:background => 'FF9994', :chart_background => '000000')
|
273
|
+
</pre>
|
274
|
+
|
275
|
+
!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)!
|
276
|
+
|
277
|
+
*Set bar/line colors*
|
278
|
+
|
279
|
+
<pre syntax="ruby">
|
280
|
+
Gchart.bar( :title => "Matt's Mojo",
|
281
|
+
:data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80],
|
282
|
+
:bar_colors => '76A4FB',
|
283
|
+
:background => 'EEEEEE', :chart_background => 'CCCCCC')
|
284
|
+
</pre>
|
285
|
+
|
286
|
+
!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)!
|
287
|
+
|
288
|
+
<pre syntax="ruby">
|
289
|
+
Gchart.line( :title => "Matt's Mojo",
|
290
|
+
:data => [15, 30, 10, 20, 100, 20, 40, 100, 90, 100, 80],
|
291
|
+
:line_colors => '76A4FB')
|
292
|
+
</pre>
|
293
|
+
|
294
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:JSGM9MY929w&chco=76A4FB&chtt=Matt's+Mojo(line colors)!
|
295
|
+
|
296
|
+
*legend / labels*
|
297
|
+
|
298
|
+
<pre syntax="ruby">
|
299
|
+
Gchart.bar( :title => "Matt vs Rob",
|
300
|
+
:data => [[300, 100, 30, 200], [100, 200, 300, 10]],
|
301
|
+
:bar_colors => 'FF0000,00FF00',
|
302
|
+
:stacked => false, :size => '400x200',
|
303
|
+
:legend => ["Matt's Mojo", "Rob's Mojo"] )
|
304
|
+
</pre>
|
305
|
+
!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)!
|
306
|
+
|
307
|
+
<pre syntax="ruby">
|
308
|
+
Gchart.line( :title => "Matt vs Rob",
|
309
|
+
:data => [[300, 100, 30, 200], [100, 200, 300, 10]],
|
310
|
+
:bar_colors => ['FF0000','00FF00'],
|
311
|
+
:stacked => false, :size => '400x200',
|
312
|
+
:legend => ["Matt's Mojo", "Rob's Mojo"] )
|
313
|
+
</pre>
|
314
|
+
!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)!
|
315
|
+
|
316
|
+
|
317
|
+
<pre syntax="ruby">
|
318
|
+
Gchart.pie_3d( :title => 'ruby_fu', :size => '400x200',
|
319
|
+
:data => [10, 45, 45], :labels => ["DHH", "Rob", "Matt"] )
|
320
|
+
</pre>
|
321
|
+
|
322
|
+
!http://chart.apis.google.com/chart?cht=p3&chl=DHH|Rob|Matt&chs=400x200&chd=s:N99&chtt=ruby_fu(labels)!
|
323
|
+
|
324
|
+
*Display axis labels*
|
325
|
+
|
326
|
+
<pre syntax="ruby">
|
327
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,y,r')
|
328
|
+
</pre>
|
329
|
+
|
330
|
+
or you can use the other syntax:
|
331
|
+
|
332
|
+
<pre syntax="ruby">
|
333
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => ['x','y','r'])
|
334
|
+
</pre>
|
335
|
+
|
336
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chxt=x,y,r&chd=s:9UGoUo9C(axis with labels)!
|
337
|
+
|
338
|
+
<pre syntax="ruby">
|
339
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x',
|
340
|
+
:axis_labels => ['Jan|July|Jan|July|Jan'])
|
341
|
+
</pre>
|
342
|
+
|
343
|
+
or you can use the other syntax:
|
344
|
+
|
345
|
+
<pre syntax="ruby">
|
346
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x',
|
347
|
+
:axis_labels => ['Jan','July','Jan','July','Jan'])
|
348
|
+
</pre>
|
349
|
+
|
350
|
+
!http://chart.apis.google.com/chart?cht=lc&chxl=0:|Jan|July|Jan|July|Jan&chs=300x200&chxt=x&chd=s:9UGoUo9C(x labels)!
|
351
|
+
|
352
|
+
*multiple axis labels*
|
353
|
+
|
354
|
+
<pre syntax="ruby">
|
355
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,r',
|
356
|
+
:axis_labels => ['Jan|July|Jan|July|Jan', '2005|2006|2007'])
|
357
|
+
</pre>
|
358
|
+
|
359
|
+
or
|
360
|
+
|
361
|
+
<pre syntax="ruby">
|
362
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,r',
|
363
|
+
:axis_labels => [['Jan','July','Jan','July','Jan'], ['2005','2006','2007']])
|
364
|
+
</pre>
|
365
|
+
|
366
|
+
!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)!
|
367
|
+
|
368
|
+
(This syntax will probably be improved in the future)
|
369
|
+
|
370
|
+
*custom params*
|
371
|
+
|
372
|
+
I certainly didn't cover the entire API, if you want to add your own params:
|
373
|
+
|
374
|
+
<pre syntax="ruby">
|
375
|
+
Gchart.line( :custom => 'chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&chls=3,6,3|1,1,0')
|
376
|
+
</pre>
|
377
|
+
|
378
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&chls=3,6,3|1,1,0(Custom)!
|
379
|
+
|
380
|
+
---
|
381
|
+
|
382
|
+
*Save the chart as a file*
|
383
|
+
|
384
|
+
You might prefer to save the chart instead of using the url, not a problem:
|
385
|
+
|
386
|
+
<pre syntax="ruby">
|
387
|
+
Gchart.line(:data => [0, 26], :format => 'file')
|
388
|
+
</pre>
|
389
|
+
|
390
|
+
You might want to specify the path and/or the filename used to save your chart:
|
391
|
+
|
392
|
+
<pre syntax="ruby">
|
393
|
+
Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_filename.png')
|
394
|
+
</pre>
|
395
|
+
|
396
|
+
*Insert as an image tag*
|
397
|
+
|
398
|
+
Because, I'm lazy, I also added a custom format:
|
399
|
+
|
400
|
+
<pre syntax="ruby">
|
401
|
+
Gchart.line(:data => [0, 26], :format => 'img_tag')
|
402
|
+
</pre>
|
403
|
+
|
404
|
+
<img src='http://chart.apis.google.com/chart?chs=300x200&chd=s:A9&cht=lc'/>
|
405
|
+
|
406
|
+
---
|
407
|
+
|
408
|
+
*Encoding*
|
409
|
+
|
410
|
+
Google Chart API offers "3 types of data encoding":http://code.google.com/apis/chart/#chart_data
|
411
|
+
|
412
|
+
* simple
|
413
|
+
* text
|
414
|
+
* extended
|
415
|
+
|
416
|
+
By default this library uses the simple encoding, if you need a different type of encoding, you can change it really easily:
|
417
|
+
|
418
|
+
default / simple: chd=s:9UGoUo9C
|
419
|
+
<pre syntax="ruby">
|
420
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10] )
|
421
|
+
</pre>
|
422
|
+
|
423
|
+
extended: chd=e:..VVGZqqVVqq..CI
|
424
|
+
<pre syntax="ruby">
|
425
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :encoding => 'extended' )
|
426
|
+
</pre>
|
427
|
+
|
428
|
+
text: chd=t:300,100,30,200,100,200,300,10
|
429
|
+
<pre syntax="ruby">
|
430
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :encoding => 'text' )
|
431
|
+
</pre>
|
432
|
+
|
433
|
+
(note that the text encoding doesn't use a max value and therefore should be under 100)
|
434
|
+
|
435
|
+
*Max value*
|
436
|
+
|
437
|
+
Simple and extended encoding support the max value option.
|
438
|
+
|
439
|
+
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.
|
440
|
+
|
441
|
+
<pre syntax="ruby">
|
442
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10] )
|
443
|
+
</pre>
|
444
|
+
|
445
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:9UGoUo9C(Title)!
|
446
|
+
|
447
|
+
<pre syntax="ruby">
|
448
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :max_value => 500 )
|
449
|
+
</pre>
|
450
|
+
|
451
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:kMDYMYkB(max 500)!
|
452
|
+
|
453
|
+
<pre syntax="ruby">
|
454
|
+
Gchart.line( :data => [100, 20, 30, 20, 10, 14, 30, 10], :max_value => false )
|
455
|
+
</pre>
|
456
|
+
|
457
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:_UeUKOeK(real size)!
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
h2. Repository
|
462
|
+
|
463
|
+
The trunk repository is <code>http://github.com/matta/googlecharts/</code> for anonymous access.
|
464
|
+
|
465
|
+
h2. License
|
466
|
+
|
467
|
+
This code is free to use under the terms of the MIT license.
|
468
|
+
|
469
|
+
h2. Contact
|
470
|
+
|
471
|
+
Comments are welcome. Send an email to "Matt Aimonetti":mailto:mattaimonetti@gmail.com
|
472
|
+
|
473
|
+
h3. Contributors
|
474
|
+
|
475
|
+
"David Grandinetti":http://github.com/dbgrandi
|
476
|
+
"Toby Sterrett":http://github.com/takeo
|