Chartjs-Loading csv file into chart.js

0👍

You can use d3-fetch to get the csv data, assuming the csv file is in public directory present in project root directory:


import { csv } from "d3-fetch";

function fetchData() {
    return csv('/filename.csv').then((data) => (data));
}

export default fetchData;

You can use await to get results from fetch data, or use then to get data when fetch is resolved.

let data = await fetchData();
let chartDataHolder;
fetchData.then((result) => {
   chartDataHolder = result; 
});

Hope this helps.

Leave a comment