Dynamic Data in Highcharts

I have a chart page with 12 charts on it. Each chart is in a self
contained partial. Each chart is a different group of data however the
common filter is a date range which I pass into the partial.

I implemented a jQRangeSlider to select the date range and pass that to
the controller which in turn re-renders the page.

I can't seem to get the charts to refresh showing the new data. I can
see in the terminal window the queries being called and they have the
right date however the chart is not refreshing.

HELP !!!


Part of the Controller

Your using a $.ajax call but not handling the response in any way. It also seems that the data for your charts is being driven by instance variables from the controller. This means that the data is set for the chart once, when the page is rendered and then never again.

I think what you want to do here is have your front-end charts populated through an ajax call, wrapped in a method. This same method is used when you need to refresh the data on the page. Essentially the HTML is rendered to give you the page structure and populate this with data using the ajax call, as opposed to using iVars from the controller. Take a look at the jQuery documentation to get an idea on how to handle the ajax response. You will want to write handler code for error responses as well to improve your debugging experience.

Does this make sense/help you out? If not I can toss a small example of what I’m talking about here.

Also jQuery documentation for ajax method can be found here - http://api.jquery.com/jquery.ajax/

I think I understand what you are saying to do, but an example would be
helpful... I am far from a JQuery expert... :slight_smile:


So in your _chart8 partial you are populating chart.series.data using the proved startdate and enddate variables. You will want to change these values when your ajax function returns data meaning you should first persist your chart object instead of just creating it without assignment.

Something simple would be

$(function() {
window.chart8 = new Highcharts.Chart({

// etc…

Once this chart is accessible you can update your ajax query to do something like this (forgive me I’m not familiar with the Chart API you are using)

url: “/charts”,
type: ‘POST’,
data: { startdate: newstartdate, enddate : newenddate},
cache: false,
dataType: ‘json’
}).done(function(data) {

window.chart8.series.data = data // or some such thing

}).fail(function(msg) {

//something went wrong with the request


Again browse through the documentation at http://api.jquery.com/jquery.ajax/

Hope this gives you a good direction.

Thank you. I assumed that was what you were saying... Let me play with
that idea and see if I can get that to work.