user3378649
user3378649

Reputation: 5354

How can I use D3.CSV to get values

I am using Angular-js to construct charts, I need to read CSV file, trasform it using js functions. Then plot the data

I need to know if I can return values from D3.CSV

 d3.csv("example.csv", function (error, data) {
    console.log(data) // this will output the data contained in your csv
    //return data;
    });

How can I call this function in middle of the other function

function doSomethingWithRows(rows) {
  // How to call data here. 
}

Upvotes: 0

Views: 1302

Answers (1)

Lars Kotthoff
Lars Kotthoff

Reputation: 109292

d3.csv is an asynchronous function. That is, it runs when the callback returns, rather than in the sequence it appears in the file. Therefore, you need to do any processing of the data within the callback. In your case, you can do something like this:

d3.csv("example.csv", function (error, data) {
  doSomethingWithRows(data);
});

Upvotes: 2

Related Questions