1

I just downloaded d3 because I want to read a csv file that contains only one column filled with 20 random numbers. It looks like this:

number
  23
  1
  5
  10
  13

The code I have so far is below (which I mimicked from this stackoverflow page:

var d3 = require("d3");
var field = [];

d3.csv("numbers.csv",function(csv){

    csv.map(function(d){

        field.push(+d.number);

    })

    console.log("field",field);

});

I wasn't sure how to run it, so I downloaded Node.js and in the Node.js command prompt, when I type in 'node number.js' (which I named my file), I get

field [ NaN, NaN, NaN ]

If I take out the '+' in front of "d.number," I get a bunch of 'undefined' in place of the 'NaN'. What did I do wrong? =(

4
  • The D3 part of it works just fine, check the fiddle: jsfiddle.net/gerardofurtado/paws24sc Your problem lies elsewhere. Commented Dec 16, 2016 at 6:51
  • Thank you for your response! I'm sorry, I'm unfamiliar with fiddle. Is there a way to see the output of your code? (I can't get anything when I click on the run button). Also, by the way you set up your code, should I not try to do this all through one .js file, but instead try to do it through an html and js file? Thank you for your time! Commented Dec 16, 2016 at 7:01
  • 1
    Press f12 (Chrome, Firefox) and check the console. Commented Dec 16, 2016 at 7:05
  • Ah, I appreciate it, thank you. Commented Dec 16, 2016 at 7:11

0

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.