1

I am trying to load titanic data into d3. I am writing the following in the chrome console:

    d3.csv("titanic_data.csv");

The data and html file are in the same folder and the server i set up is in that folder too. The function returns this: Output

How do I get the csv function to return the actual data?

1 Answer 1

2

You have 2 options:

(1) provide a callback:

d3.csv("titanic_data.csv", function(error, data) {
    if (error) {
        console.log("something went wrong", error);
    } else {
        console.log("data: ", data);
    }
})

or

(2) invoke get:

d3.csv("titanic_data.csv")
  .get(function(error, data) {
    if (error) {
        console.log("something went wrong", error);
    } else {
        console.log("data: ", data);
    }
})

Why this way? From d3.csv documentation:

d3.csv(url[[, accessor], callback])

Issues an HTTP GET (...) The request is processed asynchronously, such that this method returns immediately after opening the request. When the CSV data is available, the specified callback will be invoked with the parsed rows as the argument.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.