Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
97
rated 0 times [  101] [ 4]  / answers: 1 / hits: 7969  / 11 Years ago, sun, december 8, 2013, 12:00:00

I'm building an interactive graph that as the axis' values has two header values. It would be really better if I could chose the axis values from a drop down menu or something like that. What I don't know is if it's possible to access the header values of my csv like if they were part of an array, so I can make a dropdown menu to select from. Given a .csv that has many header values, and all of them are strings, is it possible to achieve this by using d3.csv.formatRows(rows)? I tried to use this inside the callback function with this:



var header = d3.csv(MyCsvFile.csv).formatRows(0);
console.log(header);


but didn't work. I'm not even sure I'm using the correct function, or if there is a function to do so! Any help is appreciated! Thanks!


More From » csv

 Answers
10

The documentation mentions the format that d3.csv.parse produces -- basically you will have key-value pairs with the header names as the keys. So all you need to do to get the header names is something like this.



d3.csv(foo.csv, function(error, data) {
var headerNames = d3.keys(data[0]);
});

[#49727] Saturday, December 7, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iselauniquef

Total Points: 443
Total Questions: 98
Total Answers: 102

Location: Saint Vincent and the Grenadines
Member since Thu, Oct 15, 2020
4 Years ago
;