I am trying to pass data from CSV via Axios to Apexcharts and cannot figure out what am I doing wrong. I am working with this question but cannot make it work.
I need to get the CSV data into const lst
that will hold the data outside of any function, so that I can then use it in parameters for the Apexchart.
No matter what way I try to do it, lst
will not hold the data when console.log'd outside of the function.
What is wrong?
const lst = []; // need to fill this
const populateData = (data) => {lst.push(data)} // from the other question but makes no difference
function csvJSON(csvStr){
...
// this is necessary to format the CSV into a form that apexcharts understand
populateData(x);
populateData(y); // tried with .push directly too, none works
// if I console.log here, the data is there, but cannot return it
// I thought the populateData handles the thing that axios returns Promise, but clearly it doesn't
}
function getCSV(endpoint){
axios.get(endpoint).then( function(res){
csvJSON(res.data);
});
}
getCSV("https://example/data.csv");
console.log(lst) // is empty