如何在 Rails 中使用 google_chart gem
我正在尝试使用 google_charts gem 表示数据,但它似乎对我不起作用,我复制了示例rdoc 中的代码并尝试了它,我不断收到错误 undefined methodie_chart for #<#
<% pie_chart( [ [:eggs, 3], [:bacon, 1] ], { :height => 300, :is3D => true }, { :id => "breakfastChart" } ) do |c| -%>
<% c.title "breakfast" %>
<% c.label "ingredient", :first %>
<% c.value "amount", :last %>
<% end -%>
但如果我这样尝试,我会不断收到相同的错误消息。
<% Googlecharts.pie_chart( [ [:eggs, 3], [:bacon, 1] ], { :height => 300, :is3D => true }, { :id => "breakfastChart" } ) do |c| -%>
<% c.title "breakfast" %>
<% c.label "ingredient", :first %>
<% c.value "amount", :last %>
<% end -%>
我承认我是第一次使用这个 gem,因为它是其中最新的,我通常使用 googlecharts gem,它对我来说工作得很好,但不想使用它,因为它使用图表的 url,并且不经常维护。所以现在我想在我的歌曲模型中使用以下代码示例在条形图中表示以下数据
# Return the percentage of responses that are yes. Output is a whole integer.
def percentage_yes
return 0 if yes_count == 0
((yes_count.to_f / replies_count) * 100).to_i
end
# Return the percentage of responses that are no. Output is a whole integer.
def percentage_no
return 0 if no_count == 0
100 - percentage_yes
end
# Return a chart showing the yes/no breakdown of responses
def chart_responses
chart = GoogleChart.pie_400x150(["#{percentage_yes}% yes", percentage_yes], ["#{percentage_no}% no", percentage_no])
chart.colors = ['BCDEA5', 'E6F9BC']
return chart
end
如何使用 google_charts gem 在使用此特定 gem 的条形图中表示chart_responses
。
I am trying to represent data using the google_charts gem but it does not seem to work for me i copied the sample code in the rdoc and tried it, i keep getting the error undefined method pie_chart for #<#<Class:0xa8241b4>:0xa828a0c>
<% pie_chart( [ [:eggs, 3], [:bacon, 1] ], { :height => 300, :is3D => true }, { :id => "breakfastChart" } ) do |c| -%>
<% c.title "breakfast" %>
<% c.label "ingredient", :first %>
<% c.value "amount", :last %>
<% end -%>
but if i try it this way i keep getting the same error message.
<% Googlecharts.pie_chart( [ [:eggs, 3], [:bacon, 1] ], { :height => 300, :is3D => true }, { :id => "breakfastChart" } ) do |c| -%>
<% c.title "breakfast" %>
<% c.label "ingredient", :first %>
<% c.value "amount", :last %>
<% end -%>
I admit i am using this gem for the first time because it is the most recent of them all i usually use the googlecharts gem and it works fine for me but do not want to use it cos it uses urls for the chart and it is not frequently maintained. So now i want to represent the following data in a bar chart with the following code sample in my song model
# Return the percentage of responses that are yes. Output is a whole integer.
def percentage_yes
return 0 if yes_count == 0
((yes_count.to_f / replies_count) * 100).to_i
end
# Return the percentage of responses that are no. Output is a whole integer.
def percentage_no
return 0 if no_count == 0
100 - percentage_yes
end
# Return a chart showing the yes/no breakdown of responses
def chart_responses
chart = GoogleChart.pie_400x150(["#{percentage_yes}% yes", percentage_yes], ["#{percentage_no}% no", percentage_no])
chart.colors = ['BCDEA5', 'E6F9BC']
return chart
end
How can i use the google_charts gem to represent the chart_responses
in a bar chart using this particular gem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论