Im currently working on a project with had a chart showing the total value of sales on the current year. I need 2 new features, a checkbox who load another line on the chart with get the previous period, like when the chart get one year period, i need the last year too when checked, when its month, last month when checked and so on. Im using the VUE tool, Vchart, to get the charts running and the project are being build on Rails. Any advise?
home_controller.rb
def graph_sales
months = t :abbr_month_names, scope: 'date'
render json: { items: @current_account.orders.group('month')
.select("month(created_at) as month, sum(total_cents) as profit")
.where(created_at: Date.today.beginning_of_year..Date.today.end_of_year)
.map{|item| {
date: months[item.month],
profit: item.profit
}}
} end
Aucun commentaire:
Enregistrer un commentaire