我有四个团队,每个团队有四个人,我正在尝试为每个团队创建一个图表,@all
通过团队 ID 从团队和组中选择每个人,所以这个循环将产生 4 次迭代,我试图总结每个团队的目标、预测和实现的数字:
<% @all.each do |a| %>
<div style="width:100%; height: 900px; overflow: auto;">
<br>
<h1>
<%= Date.today.strftime("%B") %>
Sales : <%= a.team.name %>
</h1>
<canvas id="<%= a.team.name %>" height="800" width="1000"></canvas>
<% @main = Individual.find(:all, :conditions => "team_id = '#{a.team_id}'")%>
<script>
var target = <%= @main.sum(:target) %>;
var forecast = <%= @main.sum(:forecast) %>;
var achieved = <%= @main.sum(:achieved) %>;
var barChartData = {
labels : ["Target", "Forecast", "Achieved"],
datasets : [{
fillColor : "rgba(237,28,36,1)",
strokeColor : "rgba(237,28,36,1)",
data : [target, forecast, achieved]
}]
}
var opt = {
scaleFontFamily : "'Trebuchet'",
scaleFontSize : 20,
scaleFontColor : "#fff",
}
var myLine = new Chart(document.getElementById("<%= a.team.name %>").getContext("2d")).Bar(barChartData, opt);
</script>
</div>
<% end %>
但我得到这个错误undefined method '+' for #<Individual:0x007ff08c8164e0>
如果我分别遍历每个人,它会显示正确的数字,只是不会将它们相加。