I’ve set up some charts using highcharts, populating it’s series column using the brilliant ‘gon’ gem. Now, i’m trying to update it’s results using ajax.
Here’s what my setup looks like:
user_controller:
gon.segmentedData = ActiveRecord query here..
application.js
var weekly_options = { //Some standard highcharts options here
series: gon.segmentedData
};
This renders the chart perfectly. I want to ajaxify this chart using the following action
view:
<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..' %>
To get updated data to the chart, i re-populate series data in the transaction_controller’s create action
transaction_controller
def create
gon.segmentedData = ..
end
create.js :
var options = //here i pass all the options again
new Highcharts.Chart(options);
My problem is that i’m unable to get an updated set of options to create.js through the transaction_controller. The same chart gets rendered again.
Would highly appreciate if someone could critique this approach for me.
I had problems fetching updated data from my controllers to populate my highcharts data. Instead of using gon, which kept returning stale data, I switched to json. Works like a charm now.