
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.63 KB | hits: 7 | expires: Never
How to re-render a graph at a given interval that retrieves data from a controller in Rails?
var ajax_path = #{action_controller_path}
function pollData() {
$.ajax({
type: 'get',
url: ajax_path,
success: function(data) {
// update chart
var series = chart.series[0],
shift = series.data.length > 20; // shift if the series is longer than 20
chart.series[0].addPoint(data, true, shift);
setTimeout(pollData, 60000) // Poll data every 60s
}
});
}
respond_to :json, only: [:polling_action]
def polling_action
@data_point = Model.get_data
respond_with @data_point
end