【问题标题】:Updating highcharts using ajax for Rails使用 ajax for Rails 更新 highcharts
【发布时间】:2012-03-15 18:18:09
【问题描述】:

我使用 highcharts 设置了一些图表,并使用出色的 'gon' gem 填充它的系列列。现在,我正在尝试使用 ajax 更新它的结果。

我的设置如下所示:

用户控制器:

gon.segmentedData = ActiveRecord query here..

application.js

var weekly_options = {  //Some standard highcharts options here


                    series: gon.segmentedData  
                };

这可以完美地呈现图表。我想使用以下操作 ajaxify 这个图表

查看:

<div class = deposit>
<%= form_tag transact_path, :remote => true, :validate => true, :method => :post do %>
.
.
.
 <%= submit_tag "Deposit", :id => 'deposit_button', :class => 'round', :disable_with => 'Please wait..' %> 

为了获取图表的更新数据,我在 transaction_controller 的创建操作中重新填充系列数据

transaction_controller

def create
 gon.segmentedData = ..
end

create.js:

   var options = //here i pass all the options again

    new Highcharts.Chart(options);

我的问题是我无法通过 transaction_controller 获得一组更新的 create.js 选项。再次呈现相同的图表。

如果有人可以为我批评这种方法,我们将不胜感激。

【问题讨论】:

    标签: ruby-on-rails ajax highcharts


    【解决方案1】:

    使用惰性高图表来节省您的时间!

    https://github.com/michelson/lazy_high_charts

    例如 在控制器中,

    @h = LazyHighCharts::HighChart.new('graph') do |f|
    f.options[:chart][:defaultSeriesType] = "area"
    f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
    f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
    end
    

    在看来,

    <%= high_chart("my_id", @h) %>
    

    【讨论】:

    • 谢谢!看起来很有希望!
    【解决方案2】:

    我在从控制器获取更新数据以填充我的 highcharts 数据时遇到问题。我没有使用不断返回陈旧数据的 gon,而是改用 json。现在就像一个魅力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-18
      • 2014-11-29
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多