score:2

when django return rendered template to client, it won't be able to make any changes afterwards. that's why your chart doesn't reflect any changes made in django.

if you need to update your chart with new data, easiest solution will be to use ajax request.

  • user press refresh button
  • javascript send get request to django api point
  • django serve new values in json back to user
  • javascript will update chart with new values

make another endpoint, something like this:

from django.http import jsonresponse

def dashboard_ajax_chart_data(request):
    pass_tc=500
    failed_tc=99
    inprogress_tc=50
    data = {'data':[pass_tc, failed_tc, inprogress_tc]}
    return jsonresponse(data)

make function in your javascript code, like this:

jquery('.refresh-button').click(function(){
        jquery.getjson("/dashboard_ajax/", function(data, status)
        {
            chart.data.datasets[0].data = data.data;
            chart.update();
        }
        )
});

and make this function execute when you click on your refresh button.

i don't have proper experience with chart.js, but use this guide to update your chart. https://www.chartjs.org/docs/latest/developers/updates.html


Related Query

More Query from same tag