RubyMine 3.1 中的 Highcharts 实现

发布于 2024-10-20 04:34:12 字数 2510 浏览 0 评论 0原文

我想在 ruby​​ on Rails 中实现 highcharts。但是rails.js存在一些运行时问题

错误:Event.Handler.Prototype为null或不是rails.js中的对象

这是控制器:

class LineChartController < ApplicationController
  def index
      chart_data = [{
            :name  => 'Expense',
            :data  => [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }, {
            :name  => 'Savings',
            :data  => [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
    tooltip_formatter = '
  function() {return "<b>"+ this.series.name +"</b><br/>"+this.x +":"+ this.y +"\u00B0C";}'

@chart =  Highchart.new({
  :chart => {
            :renderTo => "container",
            :marginRight =>  130,
            :marginBottom => 25,
    #:defaultSeriesType=> "line"
        },
        :title => {
            :text => "Monthly Average Expenses",
            :x => -20
        },
        :subtitle => {
            :text => 'Source: Sample Application',
            :x => -20
        },
        :x_axis => {
            :categories => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        :y_axis => {
            :title => {
                :text => "Rs. (in 1000's)"
            },
          :plotLines => [{
                :value => 0,
                :width => 1,
                :color => '#808080'
            }]
        },
        :tooltip => {
            :formatter => tooltip_formatter
        },
        :legend => {
            :layout=> 'vertical',
            :align=> 'right',
            :verticalAlign=> 'top',
            :x=> -10,
            :y=> 100,
            :borderWidth=> 0
        },
        :series => chart_data

  })
  end
end

application.html

<head>
  <title>Graphs</title>
  <%= stylesheet_link_tag :all %>
 <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "highcharts" %>

  <%= csrf_meta_tag %>
</head>
<body>

<%= yield %>

<script type="text/javascript">
            $(document).ready(function() {

                <%= @chart %>
                <%= yield :javascript %>
            });
        </script>

</body>

问:我哪里出错了?有什么建议吗?

I want to implement highcharts in ruby on rails. But there's some runtime problem with rails.js

Error : Event.Handler.Prototype is null or not an object in rails.js

Here is the Controller :

class LineChartController < ApplicationController
  def index
      chart_data = [{
            :name  => 'Expense',
            :data  => [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }, {
            :name  => 'Savings',
            :data  => [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
    tooltip_formatter = '
  function() {return "<b>"+ this.series.name +"</b><br/>"+this.x +":"+ this.y +"\u00B0C";}'

@chart =  Highchart.new({
  :chart => {
            :renderTo => "container",
            :marginRight =>  130,
            :marginBottom => 25,
    #:defaultSeriesType=> "line"
        },
        :title => {
            :text => "Monthly Average Expenses",
            :x => -20
        },
        :subtitle => {
            :text => 'Source: Sample Application',
            :x => -20
        },
        :x_axis => {
            :categories => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        :y_axis => {
            :title => {
                :text => "Rs. (in 1000's)"
            },
          :plotLines => [{
                :value => 0,
                :width => 1,
                :color => '#808080'
            }]
        },
        :tooltip => {
            :formatter => tooltip_formatter
        },
        :legend => {
            :layout=> 'vertical',
            :align=> 'right',
            :verticalAlign=> 'top',
            :x=> -10,
            :y=> 100,
            :borderWidth=> 0
        },
        :series => chart_data

  })
  end
end

application.html

<head>
  <title>Graphs</title>
  <%= stylesheet_link_tag :all %>
 <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "highcharts" %>

  <%= csrf_meta_tag %>
</head>
<body>

<%= yield %>

<script type="text/javascript">
            $(document).ready(function() {

                <%= @chart %>
                <%= yield :javascript %>
            });
        </script>

</body>

Q : where am i going wrong? any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦妄 2024-10-27 04:34:12

你必须使用 rails.js for jQuery (rails.js。你使用的默认兼容与原型。

You have to use rails.js for jQuery (rails.js. The one you use is default compatible with Prototype.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文