Chartjs-How call a function when my array is filled

1πŸ‘

βœ…

I don’t see the rest of your code but based on your description there is one simple logical solution.

The problem is that the buildChart function runs before the getChartData function.
Solution. Call the buildChart function after getChartData function.
Pseudo code example,

const getChartData = () => {
    return new Promise((resolve) => {
        Run your HTTP request and retrieve your data
        resolve(chart data ready to be used)
    });
}
const buildChart = () => {
    // do your chart building here
}
//then you run the functions in sequence.
getChartData().then(buildChart);

Leave a comment