{"id":5911,"date":"2014-04-09T01:50:09","date_gmt":"2014-04-09T01:50:09","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/09\/d3-seems-to-assume-i-know-the-column-names-of-a-csv-collection-of-common-programming-errors\/"},"modified":"2014-04-09T01:50:09","modified_gmt":"2014-04-09T01:50:09","slug":"d3-seems-to-assume-i-know-the-column-names-of-a-csv-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/09\/d3-seems-to-assume-i-know-the-column-names-of-a-csv-collection-of-common-programming-errors\/","title":{"rendered":"d3 seems to assume I know the column names of a csv?-Collection of common programming errors"},"content":{"rendered":"<p>I have csv files that are generated, and I am trying to load them into d3 to graph them. The column names are based on the data, so I essentially can&#8217;t know them in advance. With testing, I am able to load this data and graph it all well and nice if I know the names of the columns&#8230;but I don&#8217;t in my use case.<\/p>\n<p>How can I handle this in d3? I can&#8217;t seem to find anything to help\/reference this online or in the documentation. I can see when I log to the console data[0] from d3.csv that there are two columns and the values read for them, but I don&#8217;t know how to refer arbitrarily to column 1 or 2 of the data without knowing the name of the column ahead of time. I&#8217;d like to avoid that in general, knowing my timestamps are in column 1 and my data is in column 2, if that makes sense.<\/p>\n<p>Edit, my answer uses d3.entries to help learn the name of the unknown column, and then continues to access all objects with that index:<\/p>\n<pre><code>d3.csv(\"export.csv\", function(error, data) {\n    var mappedArray = d3.entries(data[0]);\n    var valueKey = mappedArray[1].key;\n    data.forEach(function(d) {\n        ...\n        d.value = d[valueKey];\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have csv files that are generated, and I am trying to load them into d3 to graph them. The column names are based on the data, so I essentially can&#8217;t know them in advance. With testing, I am able to load this data and graph it all well and nice if I know the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5911","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5911","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5911"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5911\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}