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? =(

Community
  • 1
  • 1
xf_
  • 11
  • 2
  • The D3 part of it works just fine, check the fiddle: https://jsfiddle.net/gerardofurtado/paws24sc/ Your problem lies elsewhere. – Gerardo Furtado Dec 16 '16 at 06: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! – xf_ Dec 16 '16 at 07:01
  • 1
    Press f12 (Chrome, Firefox) and check the console. – Gerardo Furtado Dec 16 '16 at 07:05
  • Ah, I appreciate it, thank you. – xf_ Dec 16 '16 at 07:11

0 Answers0