2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsでグラフ描画に使えるgem

2
Posted at

はじめに

Rubyを使ったWebアプリにグラフを入れたいと考えたため、今回の記事に描画のやり方を投稿します。この記事が少しでも皆さんのお役に立てれば幸いです。
今回記事の作成にあたり、Chartkick公式HPを参考にしました。

描画方法

まず、ターミナルで次の二つのgemをインストールします

gem install chartkick
gem install chartable

そして、Gemfileに次の2つを追記して、bundle installします。

gem 'chartkick'
gem 'chartable'

次にapp/assets/javascripts/application.jsへ移動し、以下の2つを追記します。

//= require Chart.bundle
//= require chartkick

これで準備は整いました。
最後に、コントローラのindexアクション(アクション名は任意)に

def index
    @sample = {'2019-06-01' => 60, '2019-06-02' => 65, '2019-06-03' => 64}
  end

と記述し、viewに

<%= pie_chart @sample %>

と記述すると、
結果

終わりに

これで、今回の投稿を終わります。何かご意見等がございましたらご連絡ください。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?