Assuming that you have an http server serving the directory containing the following two files:
You may define the custom function to parse the fields of a row. The datum object contains all values of the corresponding fields within a row. You can return an object whose attributes map to a value that is within the row by simply accessing the datum's field name.
So you can define your function as follows
Example CSV:
field1,field2,field3
value1,value2,value3
value4,value5,value6
Anonymous function you could pass:
function(datum,index)
{
var collectionObject = {};
collectionObject.someFieldName = datum.field2,
collectionObject.anotherFieldName = datum.field3
return collectionObject;
}
In your case you would do the following:
test.csv
address,longitude,latitude,geometry
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
"This","is","an","example"
index.html
<!DOCTYPE html>
<meta charset="utf-8">
<head>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var csv = d3.csv("test.csv", function(d)
{
return {geometry : d.geometry};
},
function(error, rows)
{
console.log(rows);
});
console.log(csv);
</script>
</body>
</html>