Created
November 7, 2011 08:41
-
-
Save hidakatsuya/1344470 to your computer and use it in GitHub Desktop.
ThinReports Example: Google Chart API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'rubygems' | |
require 'thinreports' | |
require 'open-uri' | |
def open_chart(*params) | |
open('http://chart.googleapis.com/chart?' + URI.encode(params.join('&'))) | |
end | |
report = ThinReports::Report.new :layout => 'google_chart_api.tlf' | |
report.start_new_page do | |
# Basic Bar Chart | |
item(:bar_chart).src(open_chart('cht=bhs', | |
'chs=240x140', | |
'chco=4d89f9,c6d9fd', | |
'chd=t:10,50,60,80,40|50,60,100,40,20', | |
'chds=0,160')) | |
# Basic Line Chart | |
item(:line_chart).value(open_chart('cht=lc', | |
'chs=240x140', | |
'chd=t:40,60,60,45,47,75,70,72')) | |
# Basic Pie and Radar Chart | |
values(:pie_chart => open_chart('cht=p', | |
'chs=240x140', | |
'chdl=30°|40°|50°|60°', | |
'chd=s:Uf9a', | |
'chl=1月|2月|3月|4月'), | |
:radar_chart => open_chart('cht=r', | |
'chs=140x140', | |
'chd=t:80,30,99,60,50,20', | |
'chls=3,0,0', | |
'chxt=x,y', | |
'chxl=0:|Str|Vit|Agi|Dex|Int|Lux|1:|||||', | |
'chm=B,FF990080,0,0,5')) | |
# 3D-Pie Chart | |
item(:pie_3d_chart).src(open_chart('cht=p3', | |
'chs=250x140', | |
'chd=t:21,55.3,18,5.7', | |
'chco=0092b9,86ad00,f2b705,bc3603', | |
'chl=春|夏|秋|冬')) | |
# QR Code | |
item(:qr_code).src(open_chart('cht=qr', | |
'chs=150x150', | |
'chl=http://www.thinreports.org/')) | |
end | |
report.generate_file('google_chart_api.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment