chartkick is a library that makes it very easy to create graphs.
Ruby 2.5.3 Ruby on Rails 5.2.4 chartkick 3.3.1
$ bundle install
//= require chartkick //= require Chart.bundle
I'm ready. You may want to shut down the server and start over with rails s.
ID, width, height
<%= line_chart data, id: "users-chart", width: "800px", height: "500px" %>
<%= line_chart data, xtitle: "Time", ytitle: "Population" %>
Combining these makes it look like this.
Prepare sales (result) and sales date (result_date) in managemant,
def index @managemants = Managemant.all end
#Data for chart kick def self.chart_date order(result_date: :asc).pluck('result_date', 'result').to_h end
<%= column_chart @managemants.chart_date, xtitle: "date", ytitle: "Earnings(Circle)", width: "600px", height: "200px" %>
You can change it to various graphs just by changing the column_chart part of the view. -Line graph-line_chart
Pie chart-pie_chart · Bar chart-pie_chart
You can easily create a beautiful graph, so please give it a try.