Adjusting payment graph

This commit is contained in:
Will Bradley 2014-04-10 21:05:14 -07:00
parent d4286e4ddf
commit b3279299cf
2 changed files with 26 additions and 19 deletions

View File

@ -45,22 +45,19 @@ class PaymentsController < ApplicationController
payment_months = @payments.sort_by(&:date).group_by{ |p| p.date.beginning_of_month } payment_months = @payments.sort_by(&:date).group_by{ |p| p.date.beginning_of_month }
@payments_by_month = [] @payments_by_month = []
payment_months.each do |month| payment_months.each do |month|
# Only grab the last year from today # Calculate sum of amounts for each month and store at end of month array
if month.first > (Date.today - 1.year) && month.first < Date.today @payments_by_month << [month.first.to_time.to_i*1000, month.last.sum{|p|
# Calculate sum of amounts for each month and store at end of month array amount = amount_or_level(p)
@payments_by_month << [month.first.to_time.to_i*1000, month.last.sum{|p| if chart_type.include?(amount)
amount = amount_or_level(p) if chart_name == "members"
if chart_type.include?(amount) 1 # Output 1 to count members
if chart_name == "members"
1 # Output 1 to count members
else
amount # Output dollars to count amount
end
else else
0 amount # Output dollars to count amount
end end
}] else
end 0
end
}]
end end
return @payments_by_month return @payments_by_month

View File

@ -6,8 +6,8 @@ $(function() {
$( "#graph" ).dialog({ $( "#graph" ).dialog({
autoOpen: false, autoOpen: false,
height: 325, height: 480,
width: 525, width: 640,
modal: true, modal: true,
}); });
$( "#graph-button" ).click(function() { $( "#graph-button" ).click(function() {
@ -16,12 +16,22 @@ $(function() {
$('#graph').highcharts({ $('#graph').highcharts({
chart: { chart: {
type: 'area' type: 'area',
zoomType : 'x',
resetZoomButton : {
position: {
align: 'left'
}
},
}, },
title: { title: {
style : { fontSize: '10px' }, style : { fontSize: '12px' },
text: "Numbers for Most Recent Month Greater Than They Appear" text: "Numbers for Most Recent Month Greater Than They Appear"
}, },
subtitle: {
style : { fontSize: '10px' },
text: "Click and Drag to Zoom."
},
xAxis: { xAxis: {
type: 'datetime' type: 'datetime'
}, },
@ -96,7 +106,7 @@ $(function() {
}); });
</script> </script>
<div id="graph" title="Payments by Month" style="height: 250px; width: 500px; float: right;"></div> <div id="graph" title="Payments by Month" style="height: 400px; width: 600px; float: right;"></div>
<h1>Listing payments <button id="graph-button" class="btn">View Graph</button></h1> <h1>Listing payments <button id="graph-button" class="btn">View Graph</button></h1>