google-charts-on-railsを試したいパート2
google-charts-on-railsを試したいにて苦労している件の続き。
前回の成功事例
コントローラー def google_chart @lc= GoogleChart.pie(10,20,40,30).to_url end ビュー <%= image_tag @lc %>
コントローラーにて1行で記述できるのは素晴らしいけど、細かくパラメーターを指定すると面倒っぽい。
複数行で記述する方法を模索する。
コントローラー temp_chart = GoogleChart.new temp_chart.type = :line temp_chart.data = [10, 20, 15, 55] temp_chart.labels = ["ほげ","あ","hoge","ううう"] @g_chart = temp_chart.to_url ビュー <%= image_tag @g_chart %>
こんな感じになった。
横棒の退部のチャートにして、バーのラベルを指定するのが目標なんだけど、
"http://chart.apis.google.com/chart?chs=200x200&cht=bhs&chl=%E3%81%
BB%E3%81%92|%E3%81%82|hoge|%E3%81%86%E3%81%86%E3%81%86&chd=t:10,20,15,55"
ラベルは「chl」で記述されている。「chxt=x,y chxl=0:|Jan|Feb|Mar|Apr|May」こんな記述が出来ないっぽい。
やりたいことが出来なさそうな予感がする。
無理矢理にコードを作成してみる
g_and = "&" @g_chart = "http://chart.apis.google.com/chart?" #chs:サイズxy=3000,000 @g_chart << "chs=300x1000" #cht:チャートの種類 @g_chart << g_and << "cht=bhg" #chd:データ @g_chart << g_and << "chd=t:10,40,60,80,100" #chxl:ラベル @g_chart << g_and << "chxt=x,y" #chxl:棒の名前 @g_chart << g_and << "chxl=1:|最初|ふが|ふにゅふにゅ|ぴよぴよ|最後"
できあがった画像は「データ」は上から、「ラベル」は下からレンダリングされている。変なの。