d3.jspromise

Convert d3.csv to promise?


Using Angular 5 and I would like to load a CSV file into the async pipe, how do I convert this to a promise?

d3.csv(this.csvFile, function(data) {
      console.log(data);
});

Solution

  • Starting with d3 version 5, promises are built in.

    d3.csv("file.csv").then(function(data) {
      console.log(data);
    });
    

    If you use async/await you can do this:

    const data = await d3.csv("file.csv");
    console.log(data);