Ruby
MacOSX
グラフ

gruffを使ってグラフ作成しようとしたら`get_type_metrics': unable to read fontって言われた

More than 3 years have passed since last update.

こちらを参考にグラフ作成してみるか〜となってやってみましたが、うまくいかず。。

http://easyramble.com/ruby-gruff-graph.html


Gemfile

source "https://rubygems.org"

gem 'gruff'


#!/usr/bin/env ruby

require 'gruff'

g = Gruff::Line.new
g.title = "My Graph"

g.data("Apples", [1, 2, 3, 4, 4, 3])
g.data("Oranges", [4, 8, 7, 9, 8, 9])
g.data("Watermelon", [2, 3, 1, 5, 6, 8])
g.data("Peaches", [9, 9, 10, 8, 7, 9])

g.labels = {0 => '2003', 2 => '2004', 4 => '2005'}

g.write('my_fruity_graph.png')

bundle install --path=vendor/bundle

bundle exec ./test.rb
/Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:1112:in `get_type_metrics': unable to read font `/usr/local/share/ghostscript/fonts/n019003l.pfb' @ error/annotate.c/RenderFreetype/1123: `(null)' (Magick::ImageMagickError)
from /Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:1112:in `calculate_caps_height'
from /Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:523:in `setup_graph_measurements'
from /Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:485:in `setup_drawing'
from /Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:450:in `draw'
from /Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/line.rb:174:in `draw'
from /Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:424:in `write'
from ./test.rb:15:in `<main>'

ググってみるとどうやらghostscriptをインストールする必要があるみたい。

brew install ghostscript

これでイケる!

と思ったら違うエラーが。。

/Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:425:in `write': unable to load module `/usr/local/Cellar/imagemagick/6.8.6-3/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1277 (Magick::ImageMagickError)

from /Users/xxx/Working/git/graphs/vendor/bundle/ruby/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:425:in `write'
from test.rb:15:in `<main>'

これはここの通りにやったら解決しました。

http://qiita.com/liubin/items/c4c0963d2b6550221682

んで無事グラフ生成できました。

めでたしめでたし。

my_fruity_graph.png