Note that there are some explanatory texts on larger screens.

plurals
  1. POCombine rows of m/d/y & integer for use with charts in ruby
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/12371279/rails-activerecord-group-by-sum-db-results-for-use-with-lazy-highcharts">Rails ActiveRecord group_by &amp; sum db results for use with Lazy HighCharts</a> </p> </blockquote> <p>I am completely new to RoR/Ruby and i am using Lazy High Charts gem to generate some purdy charts based on some database information.</p> <p>I have tried the answers that were provided but i am still a bit confused as to how to do this..</p> <p>I need to sum amount_used, and billed_amount and group by month/year (e.g; Aug/2012)</p> <p>The end result will be something similar to a dual axis chart with two series "Amount Used", and "Cost".. This information is specific to a certain account_id. </p> <p><img src="https://i.stack.imgur.com/VwUYZ.png" alt="enter image description here"></p> <h2>Invoices table</h2> <pre><code>+---------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | account_id | int(11) | YES | | NULL | | | invoice_date | varchar(255) | YES | | NULL | | | amount_used | float | YES | | NULL | | | billed_amount | float | YES | | NULL | | | comments | text | YES | | NULL | | | created_at | datetime | NO | | NULL | | | updated_at | datetime | NO | | NULL | | +---------------+--------------+------+-----+---------+----------------+ </code></pre> <h2>Controller Chart Code</h2> <pre><code>@account = Account.find(params[:id]) @invoices = Invoice.where("account_id = #{@account.id}").order("invoice_date DESC") @h = LazyHighCharts::HighChart.new('area') do |f| f.options[:chart][:defaultSeriesType] = "area" #Sample dates right now, should be the grouped_by :invoice_date f.xAxis( :categories =&gt; ['May', 'Jun', 'Jul'] ) f.yAxis([ { :title =&gt; { :text =&gt; "Amount Used" } }, { :title =&gt; { :text =&gt; "Cost" }, :opposite =&gt; true } ]) #Sample data right now, should be the summed amounts of the :amount_used correpsonding for each above grouped invoice_date f.series(:name =&gt; "Amount Used", :data =&gt; [100,300,500] ) #Sample data right now, should be the summed amounts of the :billed_amount correpsonding for each above grouped invoice date f.series(:name =&gt; "Cost", :yAxis =&gt; 1, :data =&gt; [200,400,600] ) end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload