1

http://bl.ocks.org/robschmuecker/7880033

I'm new to javascript and d3. The above example is a dendrogram. I can create my own. However, if I wanted to use it for something like employee data, it seems like it would be a pain to always having to be editing the json unless I'm missing some easier trick.

A csv in excel, that I've used in other charts, would seem like it would work well. Is It possible to replace the flare.json with a csv with the data? if so , how?

Serenity
  • 35,289
  • 20
  • 120
  • 115
Nick
  • 27
  • 1
  • 3

1 Answers1

2

No, it's not possible directly. To know why, you'll have to understand the way the function d3.csv creates an array. Suppose you have this CSV:

foo, bar, baz
21, 33, 5
1, 14, 42

When parsed, it will generate a single array of objects, without nested arrays or nested objects. The first row defines the key names, and the other rows the values. This is the array generated for that CSV:

[
  {"foo": 21, "bar": 33, "baz": 5},
  {"foo": 1, "bar": 14, "baz": 42}
]

Or, if you don't change the type, with the numbers as strings:

[
  {"foo": "21", "bar": "33", "baz": "5"},
  {"foo": "1", "bar": "14", "baz": "42"}
]

You will not get anywhere close of what you want, which is an array of objects containing arrays containing objects containing arrays etc...

You can modify this array later to create the nested children you need (look at @torresomar comment below), but it's way easier to simply edit your JSON.

Gerardo Furtado
  • 100,839
  • 9
  • 121
  • 171
  • Or write a simple program to convert one file format to another for you. That might end up being much quicker if you have to convert lots of files. – RichS May 31 '16 at 04:44
  • 1
    Yeah @GerardoFurtado is right, I was trying to give a a hierarchical approach to the CSV but it will be pretty cumbersome since CSV is not a format that will allow you hierarchy in a simple way. If you still want to stretch CSV usage you may want to check this out http://stackoverflow.com/questions/19043561/csv-data-to-nested-json-tree-in-d3 but I do not recommend it. – torresomar May 31 '16 at 04:57
  • These were great responses. Thank you so much for your help. – Nick Jun 10 '16 at 14:10