googlecharts 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +5 -1
- data/lib/gchart.rb +37 -5
- data/lib/gchart/version.rb +1 -1
- data/spec/gchart_spec.rb +35 -2
- data/website/index.html +80 -5
- data/website/index.txt +54 -2
- data/website/template.rhtml +6 -1
- metadata +43 -37
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/lib/gchart.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
require 'gchart/version'
|
3
|
+
require "open-uri"
|
4
|
+
require "uri"
|
3
5
|
|
4
6
|
class Gchart
|
5
7
|
|
@@ -10,14 +12,21 @@ class Gchart
|
|
10
12
|
@@simple_chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
|
11
13
|
@@chars = @@simple_chars + ['-', '.']
|
12
14
|
@@ext_pairs = @@chars.map { |char_1| @@chars.map { |char_2| char_1 + char_2 } }.flatten
|
15
|
+
@@file_name = 'chart.png'
|
13
16
|
|
14
17
|
attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :max_value, :bar_colors,
|
15
18
|
:title_color, :title_size, :custom, :axis_with_labels, :axis_labels
|
16
19
|
|
17
20
|
class << self
|
18
21
|
# Support for Gchart.line(:title => 'my title', :size => '400x600')
|
19
|
-
def method_missing(m, options={}
|
20
|
-
|
22
|
+
def method_missing(m, options={})
|
23
|
+
# Extract the format and optional filename, then clean the hash
|
24
|
+
format = options[:format] || 'url'
|
25
|
+
@@file_name = options[:filename] unless options[:filename].nil?
|
26
|
+
options.delete(:format)
|
27
|
+
options.delete(:filename)
|
28
|
+
# create the chart and return it in the format asked for
|
29
|
+
if @@types.include?(m.to_s)
|
21
30
|
chart = new(options.merge!({:type => m}))
|
22
31
|
chart.send(format)
|
23
32
|
elsif m.to_s == 'version'
|
@@ -92,22 +101,37 @@ class Gchart
|
|
92
101
|
@chart_angle = options[:angle]
|
93
102
|
end
|
94
103
|
end
|
95
|
-
|
104
|
+
|
96
105
|
# load all the custom aliases
|
97
106
|
require 'gchart/aliases'
|
98
107
|
|
99
108
|
protected
|
100
109
|
|
110
|
+
# Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org)
|
111
|
+
def fetch
|
112
|
+
open(query_builder) { |io| io.read }
|
113
|
+
end
|
114
|
+
|
115
|
+
# Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org)
|
116
|
+
def write(io_or_file=@@file_name)
|
117
|
+
return io_or_file.write(fetch) if io_or_file.respond_to?(:write)
|
118
|
+
open(io_or_file, "w+") { |io| io.write(fetch) }
|
119
|
+
end
|
120
|
+
|
101
121
|
# Format
|
102
122
|
|
103
123
|
def img_tag
|
104
124
|
"<img src='#{query_builder}'/>"
|
105
125
|
end
|
106
126
|
|
107
|
-
def
|
127
|
+
def url
|
108
128
|
query_builder
|
109
129
|
end
|
110
130
|
|
131
|
+
def file
|
132
|
+
write
|
133
|
+
end
|
134
|
+
|
111
135
|
#
|
112
136
|
def jstize(string)
|
113
137
|
string.gsub(' ', '+')
|
@@ -143,6 +167,7 @@ class Gchart
|
|
143
167
|
|
144
168
|
# set bar, line colors
|
145
169
|
def set_bar_colors
|
170
|
+
@bar_colors = @bar_colors.join(',') if @bar_colors.is_a?(Array)
|
146
171
|
"chco=#{@bar_colors}"
|
147
172
|
end
|
148
173
|
|
@@ -187,12 +212,19 @@ class Gchart
|
|
187
212
|
end
|
188
213
|
|
189
214
|
def set_axis_with_labels
|
215
|
+
@axis_with_labels = @axis_with_labels.join(',') if @axis_with_labels.is_a?(Array)
|
190
216
|
"chxt=#{@axis_with_labels}"
|
191
217
|
end
|
192
218
|
|
193
219
|
def set_axis_labels
|
194
220
|
labels_arr = []
|
195
|
-
axis_labels.each_with_index
|
221
|
+
axis_labels.each_with_index do |labels,index|
|
222
|
+
if labels.is_a?(Array)
|
223
|
+
labels_arr << "#{index}:|#{labels.join('|')}"
|
224
|
+
else
|
225
|
+
labels_arr << "#{index}:|#{labels}"
|
226
|
+
end
|
227
|
+
end
|
196
228
|
"chxl=#{labels_arr.join('|')}"
|
197
229
|
end
|
198
230
|
|
data/lib/gchart/version.rb
CHANGED
data/spec/gchart_spec.rb
CHANGED
@@ -65,11 +65,14 @@ describe "generating a default Gchart" do
|
|
65
65
|
|
66
66
|
it "should be able to set label axis" do
|
67
67
|
Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true
|
68
|
+
Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true
|
68
69
|
end
|
69
70
|
|
70
71
|
it "should be able to have axis labels" do
|
71
72
|
Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007').should be_true
|
72
73
|
Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?('chxl=0:|Jan|July|Jan|July|Jan').should be_true
|
74
|
+
Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?('chxl=0:|Jan|July|Jan|July|Jan').should be_true
|
75
|
+
Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007').should be_true
|
73
76
|
end
|
74
77
|
|
75
78
|
end
|
@@ -138,12 +141,16 @@ describe "a bar graph" do
|
|
138
141
|
end
|
139
142
|
|
140
143
|
it "should be able to have different bar colors" do
|
141
|
-
Gchart.bar(:bar_colors => 'efefef
|
142
|
-
Gchart.bar(:bar_colors => 'efefef
|
144
|
+
Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true
|
145
|
+
Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true
|
143
146
|
# alias
|
144
147
|
Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true
|
145
148
|
end
|
146
149
|
|
150
|
+
it "should be able to have different bar colors when using an array of colors" do
|
151
|
+
Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true
|
152
|
+
end
|
153
|
+
|
147
154
|
end
|
148
155
|
|
149
156
|
describe "a line chart" do
|
@@ -228,4 +235,30 @@ describe "a pie chart" do
|
|
228
235
|
Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data)
|
229
236
|
end
|
230
237
|
|
238
|
+
end
|
239
|
+
|
240
|
+
describe 'exporting a chart' do
|
241
|
+
|
242
|
+
it "should be available in the url format by default" do
|
243
|
+
Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26])
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should be available as the img tag" do
|
247
|
+
Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*)\/>/)
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should be available as a file" do
|
251
|
+
File.delete('chart.png') if File.exist?('chart.png')
|
252
|
+
Gchart.line(:data => [0, 26], :format => 'file')
|
253
|
+
File.exist?('chart.png').should be_true
|
254
|
+
File.delete('chart.png') if File.exist?('chart.png')
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should be available as a file using a custom file name" do
|
258
|
+
File.delete('custom_file_name.png') if File.exist?('custom_file_name.png')
|
259
|
+
Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png')
|
260
|
+
File.exist?('custom_file_name.png').should be_true
|
261
|
+
File.delete('custom_file_name.png') if File.exist?('custom_file_name.png')
|
262
|
+
end
|
263
|
+
|
231
264
|
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Googlecharts</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/googlecharts"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/googlecharts" class="numbers">0.
|
36
|
+
<a href="http://rubyforge.org/projects/googlecharts" class="numbers">0.2.0</a>
|
37
37
|
</div>
|
38
38
|
<h2>→ ‘Sexy Charts using Google <span class="caps">API</span> & Ruby’</h2>
|
39
39
|
|
@@ -172,6 +172,14 @@ install:
|
|
172
172
|
</pre></p>
|
173
173
|
|
174
174
|
|
175
|
+
<p>If you prefer you can use this other syntax:</p>
|
176
|
+
|
177
|
+
|
178
|
+
<p><pre class='syntax'>
|
179
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="punct">[[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]],</span> <span class="symbol">:bar_colors</span> <span class="punct">=></span> <span class="punct">['</span><span class="string">FF0000</span><span class="punct">',</span> <span class="punct">'</span><span class="string">00FF00</span><span class="punct">'])</span>
|
180
|
+
</pre></p>
|
181
|
+
|
182
|
+
|
175
183
|
<p><img src="http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00" title="colors" alt="colors" /></p>
|
176
184
|
|
177
185
|
|
@@ -360,7 +368,7 @@ Data set:
|
|
360
368
|
<p><pre class='syntax'>
|
361
369
|
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span> <span class="symbol">:title</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">Matt vs Rob</span><span class="punct">",</span>
|
362
370
|
<span class="symbol">:data</span> <span class="punct">=></span> <span class="punct">[[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">],</span> <span class="punct">[</span><span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">]],</span>
|
363
|
-
<span class="symbol">:bar_colors</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">FF0000,00FF00</span><span class="punct">',</span>
|
371
|
+
<span class="symbol">:bar_colors</span> <span class="punct">=></span> <span class="punct">['</span><span class="string">FF0000</span><span class="punct">','</span><span class="string">00FF00</span><span class="punct">'],</span>
|
364
372
|
<span class="symbol">:stacked</span> <span class="punct">=></span> <span class="constant">false</span><span class="punct">,</span> <span class="symbol">:size</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">400x200</span><span class="punct">',</span>
|
365
373
|
<span class="symbol">:legend</span> <span class="punct">=></span> <span class="punct">["</span><span class="string">Matt's Mojo</span><span class="punct">",</span> <span class="punct">"</span><span class="string">Rob's Mojo</span><span class="punct">"]</span> <span class="punct">)</span>
|
366
374
|
</pre>
|
@@ -384,6 +392,14 @@ Data set:
|
|
384
392
|
</pre></p>
|
385
393
|
|
386
394
|
|
395
|
+
<p>or you can use the other syntax:</p>
|
396
|
+
|
397
|
+
|
398
|
+
<p><pre class='syntax'>
|
399
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span> <span class="symbol">:data</span> <span class="punct">=></span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=></span> <span class="punct">['</span><span class="string">x</span><span class="punct">','</span><span class="string">y</span><span class="punct">','</span><span class="string">r</span><span class="punct">'])</span>
|
400
|
+
</pre></p>
|
401
|
+
|
402
|
+
|
387
403
|
<p><img src="http://chart.apis.google.com/chart?cht=lc&chs=300x200&chxt=x,y,r&chd=s:9UGoUo9C" title="axis with labels" alt="axis with labels" /></p>
|
388
404
|
|
389
405
|
|
@@ -393,6 +409,15 @@ Data set:
|
|
393
409
|
</pre></p>
|
394
410
|
|
395
411
|
|
412
|
+
<p>or you can use the other syntax:</p>
|
413
|
+
|
414
|
+
|
415
|
+
<p><pre class='syntax'>
|
416
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span> <span class="symbol">:data</span> <span class="punct">=></span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">x</span><span class="punct">',</span>
|
417
|
+
<span class="symbol">:axis_labels</span> <span class="punct">=></span> <span class="punct">['</span><span class="string">Jan</span><span class="punct">','</span><span class="string">July</span><span class="punct">','</span><span class="string">Jan</span><span class="punct">','</span><span class="string">July</span><span class="punct">','</span><span class="string">Jan</span><span class="punct">'])</span>
|
418
|
+
</pre></p>
|
419
|
+
|
420
|
+
|
396
421
|
<p><img src="http://chart.apis.google.com/chart?cht=lc&chxl=0:|Jan|July|Jan|July|Jan&chs=300x200&chxt=x&chd=s:9UGoUo9C" title="x labels" alt="x labels" /></p>
|
397
422
|
|
398
423
|
|
@@ -405,6 +430,15 @@ Data set:
|
|
405
430
|
</pre></p>
|
406
431
|
|
407
432
|
|
433
|
+
<p>or</p>
|
434
|
+
|
435
|
+
|
436
|
+
<p><pre class='syntax'>
|
437
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span> <span class="symbol">:data</span> <span class="punct">=></span> <span class="punct">[</span><span class="number">300</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">30</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">100</span><span class="punct">,</span> <span class="number">200</span><span class="punct">,</span> <span class="number">300</span><span class="punct">,</span> <span class="number">10</span><span class="punct">],</span> <span class="symbol">:axis_with_labels</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">x,r</span><span class="punct">',</span>
|
438
|
+
<span class="symbol">:axis_labels</span> <span class="punct">=></span> <span class="punct">[['</span><span class="string">Jan</span><span class="punct">','</span><span class="string">July</span><span class="punct">','</span><span class="string">Jan</span><span class="punct">','</span><span class="string">July</span><span class="punct">','</span><span class="string">Jan</span><span class="punct">'],</span> <span class="punct">['</span><span class="string">2005</span><span class="punct">','</span><span class="string">2006</span><span class="punct">','</span><span class="string">2007</span><span class="punct">']])</span>
|
439
|
+
</pre></p>
|
440
|
+
|
441
|
+
|
408
442
|
<p><img src="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" title="multiple axis labels" alt="multiple axis labels" /></p>
|
409
443
|
|
410
444
|
|
@@ -425,6 +459,42 @@ Data set:
|
|
425
459
|
<p><img src="http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:93zyvneTTOMJMLIJFHEAECFJGHDBFCFIERcgnpy45879,IJKNUWUWYdnswz047977315533zy1246872tnkgcaZQONHCECAAAAEII&chls=3,6,3|1,1,0" title="Custom" alt="Custom" /></p>
|
426
460
|
|
427
461
|
|
462
|
+
<hr />
|
463
|
+
|
464
|
+
|
465
|
+
<p><strong>Save the chart as a file</strong></p>
|
466
|
+
|
467
|
+
|
468
|
+
<p>You might prefer to save the chart instead of using the url, not a problem:</p>
|
469
|
+
|
470
|
+
|
471
|
+
<p><pre class='syntax'>
|
472
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">file</span><span class="punct">')</span>
|
473
|
+
</pre></p>
|
474
|
+
|
475
|
+
|
476
|
+
<p>You might want to specify the path and/or the filename used to save your chart:</p>
|
477
|
+
|
478
|
+
|
479
|
+
<p><pre class='syntax'>
|
480
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">file</span><span class="punct">',</span> <span class="symbol">:filename</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">custom_filename.png</span><span class="punct">')</span>
|
481
|
+
</pre></p>
|
482
|
+
|
483
|
+
|
484
|
+
<p><strong>Insert as an image tag</strong></p>
|
485
|
+
|
486
|
+
|
487
|
+
<p>Because, I’m lazy, I also added a custom format:</p>
|
488
|
+
|
489
|
+
|
490
|
+
<p><pre class='syntax'>
|
491
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">line</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">26</span><span class="punct">],</span> <span class="symbol">:format</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">img_tag</span><span class="punct">')</span>
|
492
|
+
</pre></p>
|
493
|
+
|
494
|
+
|
495
|
+
<p><img src=’http://chart.apis.google.com/chart?chs=300×200&chd=s:A9&cht=lc’/></p>
|
496
|
+
|
497
|
+
|
428
498
|
<hr />
|
429
499
|
|
430
500
|
|
@@ -479,7 +549,7 @@ Data set:
|
|
479
549
|
</pre></p>
|
480
550
|
|
481
551
|
|
482
|
-
<p
|
552
|
+
<p><img src="http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:9UGoUo9C" title="Title" alt="Title" /></p>
|
483
553
|
|
484
554
|
|
485
555
|
<p><pre class='syntax'>
|
@@ -515,12 +585,17 @@ Data set:
|
|
515
585
|
|
516
586
|
<p>Comments are welcome. Send an email to <a href="mailto:mattaimonetti@gmail.com">Matt Aimonetti</a></p>
|
517
587
|
<p class="coda">
|
518
|
-
<a href="mattaimonetti@gmail.com">Matt Aimonetti</a>,
|
588
|
+
<a href="mattaimonetti@gmail.com">Matt Aimonetti</a>, 19th December 2007<br>
|
519
589
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
520
590
|
</p>
|
521
591
|
</div>
|
522
592
|
|
523
|
-
|
593
|
+
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
594
|
+
</script>
|
595
|
+
<script type="text/javascript">
|
596
|
+
_uacct = "UA-179809-11";
|
597
|
+
urchinTracker();
|
598
|
+
</script>
|
524
599
|
|
525
600
|
</body>
|
526
601
|
</html>
|
data/website/index.txt
CHANGED
@@ -102,6 +102,12 @@ The problem is that by default the bars are stacked, so we need to set the color
|
|
102
102
|
Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], :bar_colors => 'FF0000,00FF00')
|
103
103
|
</pre>
|
104
104
|
|
105
|
+
If you prefer you can use this other syntax:
|
106
|
+
|
107
|
+
<pre syntax="ruby">
|
108
|
+
Gchart.bar(:data => [[300, 100, 30, 200], [100, 200, 300, 10]], :bar_colors => ['FF0000', '00FF00'])
|
109
|
+
</pre>
|
110
|
+
|
105
111
|
!http://chart.apis.google.com/chart?cht=bvs&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00(colors)!
|
106
112
|
|
107
113
|
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:
|
@@ -246,7 +252,7 @@ Supply two data sets, the first data set specifies x coordinates, the second set
|
|
246
252
|
<pre syntax="ruby">
|
247
253
|
Gchart.line( :title => "Matt vs Rob",
|
248
254
|
:data => [[300, 100, 30, 200], [100, 200, 300, 10]],
|
249
|
-
:bar_colors => 'FF0000,00FF00',
|
255
|
+
:bar_colors => ['FF0000','00FF00'],
|
250
256
|
:stacked => false, :size => '400x200',
|
251
257
|
:legend => ["Matt's Mojo", "Rob's Mojo"] )
|
252
258
|
</pre>
|
@@ -266,6 +272,12 @@ Supply two data sets, the first data set specifies x coordinates, the second set
|
|
266
272
|
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,y,r')
|
267
273
|
</pre>
|
268
274
|
|
275
|
+
or you can use the other syntax:
|
276
|
+
|
277
|
+
<pre syntax="ruby">
|
278
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => ['x','y','r'])
|
279
|
+
</pre>
|
280
|
+
|
269
281
|
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chxt=x,y,r&chd=s:9UGoUo9C(axis with labels)!
|
270
282
|
|
271
283
|
<pre syntax="ruby">
|
@@ -273,6 +285,13 @@ Supply two data sets, the first data set specifies x coordinates, the second set
|
|
273
285
|
:axis_labels => ['Jan|July|Jan|July|Jan'])
|
274
286
|
</pre>
|
275
287
|
|
288
|
+
or you can use the other syntax:
|
289
|
+
|
290
|
+
<pre syntax="ruby">
|
291
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x',
|
292
|
+
:axis_labels => ['Jan','July','Jan','July','Jan'])
|
293
|
+
</pre>
|
294
|
+
|
276
295
|
!http://chart.apis.google.com/chart?cht=lc&chxl=0:|Jan|July|Jan|July|Jan&chs=300x200&chxt=x&chd=s:9UGoUo9C(x labels)!
|
277
296
|
|
278
297
|
*multiple axis labels*
|
@@ -282,6 +301,13 @@ Supply two data sets, the first data set specifies x coordinates, the second set
|
|
282
301
|
:axis_labels => ['Jan|July|Jan|July|Jan', '2005|2006|2007'])
|
283
302
|
</pre>
|
284
303
|
|
304
|
+
or
|
305
|
+
|
306
|
+
<pre syntax="ruby">
|
307
|
+
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :axis_with_labels => 'x,r',
|
308
|
+
:axis_labels => [['Jan','July','Jan','July','Jan'], ['2005','2006','2007']])
|
309
|
+
</pre>
|
310
|
+
|
285
311
|
!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)!
|
286
312
|
|
287
313
|
(This syntax will probably be improved in the future)
|
@@ -298,6 +324,32 @@ I certainly didn't cover the entire API, if you want to add your own params:
|
|
298
324
|
|
299
325
|
---
|
300
326
|
|
327
|
+
*Save the chart as a file*
|
328
|
+
|
329
|
+
You might prefer to save the chart instead of using the url, not a problem:
|
330
|
+
|
331
|
+
<pre syntax="ruby">
|
332
|
+
Gchart.line(:data => [0, 26], :format => 'file')
|
333
|
+
</pre>
|
334
|
+
|
335
|
+
You might want to specify the path and/or the filename used to save your chart:
|
336
|
+
|
337
|
+
<pre syntax="ruby">
|
338
|
+
Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_filename.png')
|
339
|
+
</pre>
|
340
|
+
|
341
|
+
*Insert as an image tag*
|
342
|
+
|
343
|
+
Because, I'm lazy, I also added a custom format:
|
344
|
+
|
345
|
+
<pre syntax="ruby">
|
346
|
+
Gchart.line(:data => [0, 26], :format => 'img_tag')
|
347
|
+
</pre>
|
348
|
+
|
349
|
+
<img src='http://chart.apis.google.com/chart?chs=300x200&chd=s:A9&cht=lc'/>
|
350
|
+
|
351
|
+
---
|
352
|
+
|
301
353
|
*Encoding*
|
302
354
|
|
303
355
|
Google Chart API offers "3 types of data encoding":http://code.google.com/apis/chart/#chart_data
|
@@ -335,7 +387,7 @@ The max value option is a simple way of scaling your graph. The data is converte
|
|
335
387
|
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10] )
|
336
388
|
</pre>
|
337
389
|
|
338
|
-
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:9UGoUo9C(Title)
|
390
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=300x200&chd=s:9UGoUo9C(Title)!
|
339
391
|
|
340
392
|
<pre syntax="ruby">
|
341
393
|
Gchart.line( :data => [300, 100, 30, 200, 100, 200, 300, 10], :max_value => 500 )
|
data/website/template.rhtml
CHANGED
@@ -42,7 +42,12 @@
|
|
42
42
|
</p>
|
43
43
|
</div>
|
44
44
|
|
45
|
-
|
45
|
+
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
46
|
+
</script>
|
47
|
+
<script type="text/javascript">
|
48
|
+
_uacct = "UA-179809-11";
|
49
|
+
urchinTracker();
|
50
|
+
</script>
|
46
51
|
|
47
52
|
</body>
|
48
53
|
</html>
|
metadata
CHANGED
@@ -1,29 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: googlecharts
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
- lib
|
11
|
-
email: mattaimonetti@gmail.com
|
12
|
-
homepage: http://googlecharts.rubyforge.org
|
13
|
-
rubyforge_project: googlecharts
|
14
|
-
description: description of gem
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ""
|
6
|
+
authors:
|
7
|
+
- Matt Aimonetti
|
15
8
|
autorequire:
|
16
|
-
default_executable:
|
17
9
|
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
25
|
-
platform: ruby
|
26
|
-
signing_key:
|
27
10
|
cert_chain:
|
28
11
|
- |
|
29
12
|
-----BEGIN CERTIFICATE-----
|
@@ -47,9 +30,22 @@ cert_chain:
|
|
47
30
|
ZR7qHIpykzr3ezcNiWtBWw==
|
48
31
|
-----END CERTIFICATE-----
|
49
32
|
|
50
|
-
|
51
|
-
|
52
|
-
|
33
|
+
date: 2007-12-19 00:00:00 -05:00
|
34
|
+
default_executable:
|
35
|
+
dependencies: []
|
36
|
+
|
37
|
+
description: description of gem
|
38
|
+
email: mattaimonetti@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- History.txt
|
45
|
+
- License.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
48
|
+
- website/index.txt
|
53
49
|
files:
|
54
50
|
- History.txt
|
55
51
|
- License.txt
|
@@ -78,22 +74,32 @@ files:
|
|
78
74
|
- website/javascripts/rounded_corners_lite.inc.js
|
79
75
|
- website/stylesheets/screen.css
|
80
76
|
- website/template.rhtml
|
81
|
-
|
82
|
-
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://googlecharts.rubyforge.org
|
79
|
+
post_install_message:
|
83
80
|
rdoc_options:
|
84
81
|
- --main
|
85
82
|
- README.txt
|
86
|
-
|
87
|
-
-
|
88
|
-
|
89
|
-
|
90
|
-
-
|
91
|
-
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: "0"
|
96
|
+
version:
|
96
97
|
requirements: []
|
97
98
|
|
98
|
-
|
99
|
+
rubyforge_project: googlecharts
|
100
|
+
rubygems_version: 0.9.5
|
101
|
+
signing_key:
|
102
|
+
specification_version: 2
|
103
|
+
summary: description of gem
|
104
|
+
test_files: []
|
99
105
|
|
metadata.gz.sig
CHANGED
Binary file
|