Tree layout dynamically

38 views
Skip to first unread message

u s s ramaraju

unread,
Apr 25, 2017, 4:02:23 PM4/25/17
to d3-js
Hi Group,

i want to draw tree layout dynamically
but i don't want to use json/csv/tsv
i want to draw it using two arrays containing child and parent
any one have any idea how can i achieve this?

Seemant Kulleen

unread,
Apr 25, 2017, 5:13:22 PM4/25/17
to d3-js
Hi Ramaraju,

Let's see if this helps:
  • In order to create a treemap, you need data shaped by d3.hierarchy()
  • In order to create a hierarchy, you need data shaped by d3.stratify()
  • In order to stratify, you need to combine your two arrays into a single array of objects that looks something like this (from the d3.stratify() docs):
[
  {"name": "Eve",   "parent": ""},
  {"name": "Cain",  "parent": "Eve"},
  {"name": "Seth",  "parent": "Eve"},
  {"name": "Enos",  "parent": "Seth"}
]

Are you able to do that?

Cheers,
Seemant

--
Oakland Finish Up Weekend
Be Amazed.  Be Amazing.
Get Mentored | Get Inspired | Finish Up
http://oaklandfinishup.com


--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages