score:0
based on your input, i guess first request is calling home
view and loads initial set data - which is then displayed on html page. on the other hand, then you are using chartdata
api view. if this scenario is right - then:
the problem in chartdata
is that, this part time, set1 , set2 , set3 = get_sets()
is executed one time when django is initialized (as described). what you need is to get sets each time when request is sent. and the code fragment is executing upon request is in get
method.
right solution would look like this:
class chartdata(apiview):
authentication_classes = []
permission_classes = []
sets = sets.objects.all()
def get(self, request, format=none):
time, set1 , set2 , set3 = get_sets()
data = {
"time": time,
"set1": set1,
"set2": set2,
"set3": set3
}
return response(data)
there is no need for extra class variables (self.set1
...). and the get_sets
function is called each time request reaches the get
method.
update (based on comment)
to avoid loading whole data each time request is handled by api view - i would keep track of last record received in frontend and based on last record id (there may be another field) i would fetch records created after the id you're tracking in frontend.
Source: stackoverflow.com
Related Query
- How to update your django page by looking for new data in the db?
- How to add labels for only some of the data point?
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
- Chart.JS: How can I only display data labels when the bar width is big enough for the text?
- How can I change the label name when you hover your data in Chart.js?
- How to clear the data for a angular-chart
- Chart.JS: How can I only display data labels when the doughnut size is big enough for the text?
- How to update only new data in Chart.JS?
- chartjs how to update dynamically data from database(Chartjs cant get the data)
- How to add left padding for my charts done in ChartJs and my Google Map so it is not glued to the limit of the page on the left
- How to render multiple Chart.JS charts on the same page with AJAX data and variables
- How to set the data of chart in angular which is taken from the backend nodejs api that is store in mongodb and showing on the html page
- Django integration with Charts.js, I'm unable to find the syntax for passing the data to the template
- Chartjs - How to update the data from values in my database?
- How to update chart at the end of every for loop in Chart.js?
- Live update the charts.js graph on a web page using json data received from a remote server
- how do i use the numbers i key in from a form as the input data for chartjs
- chart js tooltip how to control the data that show
- Chart JS show multiple data points for the same label
- How to show Y axis ticks for every point in the graph
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- How to hide Chart.js data labels for small screens
- PrimeNg bar chart how to show a label for the y-axis
- Chart.js canvas, how can I swap data without the previous data affecting my hover events?
- How to show only the data points that have a change in Chartjs?
- How can I display the xAxes and yAxes data in the tooltip, Chart JS?
- How to get rid of the white square outline or border in the tooltip for chartjs?
- How to update data Chart in async way in Angular Chart.js?
- Chart.js – how to remove data entries from the tooltip?
More Query from same tag
- chartjs time cartesian axis adapter and date library setup
- Realtime chart JS in Java obtaining the data from a sensor ;Chart.js: Failed to create chart: can't acquire context from the given item
- ChartJs chart won't update new values
- Cleart Chart data upon ajax call
- Relative bar chart overlay on line chart in chart.js
- Chartjs extended doughnut with text tooltip issue
- Display chart data based on API call
- How can I make my chart's axes use the same proportions for scaling?
- Chart to update from a drop down selection
- Two Y-axis not aligning correctly
- chart js onclick function call
- How to filter Chart JavaScript Dashboard by Year through dropdown after the MySQL count query?
- how to display labels at top of charts(chart.js)
- display ng2 chart when the property of data returned is >=0
- How to clear the data for a angular-chart
- I want to see all the labels on the X-axis of my graph in Chart.js, but only a few of the labels are coming.
- Put chart.js chart inside JQuery tooltip?
- Chartjs not displaying timed data
- Passing data in array that came from an array to chartjs with django
- Charts.js - Bar chart different colors for value intervals not working
- Wrong display of xAxes in Chartjs
- Line chart disable interpolation
- How to use GET method to choose the right table to show ChartJS graph?
- Angular 9: Chart.js: Monochromatic(Single color with shades) doughnut chart
- Chartjs unexpected resize and crop after updating data. Using laravel blade view and Livewire
- How to access all data in a function with ChartJs?
- Add Link to X-Label Chart.js
- cannot view graph using toArray()
- Generating different chart results on fly causes flickering
- chart.js 2 - Is it possible to format tick labels with HTML?