2012-02-25 73 views
1

我已经使用highcharts设置了一些图表,使用辉煌的'gon'宝石来填充它的系列栏目。现在,我试图用ajax更新它的结果。使用ajax for rails更新highcharts

这里是我的设置是什么样子:

user_controller:

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。同样的图表再次呈现。

非常感谢,如果有人可以批评这种方法对我来说。

回答

1

我有问题,从我的控制器获取更新的数据来填充我的highcharts数据。我没有使用gon,它保持返回的陈旧数据,而是转而使用json。现在就像魅力一样。

0

使用lazy-high-chart来节省您的时间!

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) %> 
+0

谢谢!看起来很有希望! – Rahul 2012-04-06 04:23:34