如何在 Rails 中使用 google_chart gem

发布于 2024-12-28 20:02:11 字数 1827 浏览 6 评论 0原文

我正在尝试使用 google_charts gem 表示数据,但它似乎对我不起作用,我复制了示例rdoc 中的代码并尝试了它,我不断收到错误 undefined methodie_chart for #<#: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 -%>

但如果我这样尝试,我会不断收到相同的错误消息。

  <% 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文