Live Data Access Posting requests and handling data responses into live charts
Live Chart Updates with Asynchronous Data Updates
The charts page in the sadjdemo application shows how to link up a Django server via Ajax calls.
There are two examples. The first refreshes all the data into the chart with each call. The browser calls the Django server repeatedly, and receives back asynchronous data messages, each of which contains the full data-set for the chart. The second example adds to the existing data in the chart after each call, deleting older data points to keep a constant duration of displayed data.
In this case, the script on the page contains the following line:
sadj$.utils.ajaxPOST("api/chartData/", JSON.stringify(payload), "sadj_charts", demoLineUpdate)
sadjdemo Django app then contains the url definition:
alongside the code at
demo_views.chart_data which actually returns new data in response to the call.
The Django-side code tracks the last set of values sent, so each data sample is within a reasonable range of the previous one. Note that you do not need to be logged in for this to work, Django can track per-session variables for anonymous users using the session ID based on session cookies.