How do I convert strings from csv in d3.js and be able to use them as a dataset? -


sorry if seems obvious, i'm new d3 , computer programming in general... have csv file has number values, when show strings in console.

i tried putting parsefloat function in code, data shows nan on console each entry.

this code:

var dataset =d3.csv("file.csv", function(d){return{data: parsefloat(d)}; },  function(data){      console.log(data);       }); 

my data looks in 1 column csv file:

9.96e-001 9.95e-001 9.95e-001 9.95e-001 9.96e-001 9.95e-001 9.96e-001 9.94e-001 9.96e-001 9.95e-001 9.94e-001 9.96e-001 1.00e+000 

obviously need make them have integer values them work dataset, can't them have number values instead of strings?

javascript should able understand numbers formatted if cast them numbers:

var dataset = d3.csv("file.csv", function(data){   data.foreach(function(d){ d['columnname'] = +d['columnname']; });      console.log(data);      }); 

where 'columnname' refers title of column the numbers.

if doesn't work, try posting csv can see if else going wrong.


Comments