this is an asynchronous vs synchorous error. this tutorial may help a bit.

take a look at this part of the code:

function bardata(url){
    let data_labels = [];
    let data_values = [];
        url: url,
        type: 'get',
        async: false,
        success: function(bar_data){
            data_labels= bar_data.labels;
            data_values= bar_data.values;
    return {data_labels,data_values};

the return {data_labels,data_values}; is actually happening before the $.ajax call. if you want to return the results from the server this line should be inside the success function of the ajax call. take a look at this question where the op has the same issue.

about updating a chart, here is a demo with a mocked server response that updates its values each second:

Related Query

More Query from same tag