Aravind
Aravind

Reputation: 1401

how to reload a graph to show updated data each time the column in database gets updated

I am using chart-kick to generate graphs in my Ruby on Rails application. I am able to display the charts without any problem. The issue is I am in need to refresh the page which has the graph each time the data is added to see the updated graph. How do I make sure that the graph alone reloads everytime I update new data in my database? Is that possible?


Note: Highcharts is not an option. I am giving this to a commercial website and they can't afford Highcharts.

Upvotes: 4

Views: 1309

Answers (4)

Aravind
Aravind

Reputation: 1401

I ended up using Chart.js and using Ajax requests to poll the database and update the graph for its changes. I was not successfull in implementing Websockets.

Upvotes: 2

Paulo Fidalgo
Paulo Fidalgo

Reputation: 22296

To achieve what you want, you need a bidirectional communication between your server and your client. I will suggest you to use websockets, it suffers from not being supported by all browsers but as fallback you can use polling the server for new results (if you care enough for a fallback). To check the current support status check this page.

Follow this example on websocket-rails gem to get started.

Upvotes: 1

user2915448
user2915448

Reputation: 1

Use turbolinks for reload graph

Upvotes: 0

DickieBoy
DickieBoy

Reputation: 4956

I would use something like pusher its for doing exactly what you need.

Upvotes: 0

Related Questions