Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8103911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:41:02+00:00 2026-06-05T23:41:02+00:00

While following numerous D3 examples, data usually gets formatted in the format given in

  • 0

While following numerous D3 examples, data usually gets formatted in the format given in flare.json:

{
 "name": "flare",
 "children": [
  {
   "name": "analytics",
   "children": [
    {
     "name": "cluster",
     "children": [
      {"name": "AgglomerativeCluster", "size": 3938},
      :

I have an adjacency list as follows:

A1 A2
A2 A3
A2 A4

which I want to convert to the above format. Currently, I am doing this on the server-side but is there a way to achieve this using d3’s functions? I found one here, but the approach seems to require modification of the d3 core library which I am not in favor due to maintainability. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:41:04+00:00Added an answer on June 5, 2026 at 11:41 pm

    There’s no prescribed format, as you can usually redefine your data through various accessor functions (such as hierarchy.children) and array.map. But the format you quoted is probably the most convenient representation for trees because it works with the default accessors.

    The first question is whether you intend to display a graph or a tree. For graphs, the data structure is defined in terms of nodes and links. For trees, the input to the layout is the root node, which may have an array of child nodes, and whose leaf nodes have an associated value.

    If you want to display a graph, and all you have is a list of edges, then you’ll want to iterate over the edges in order to produce an array of nodes and an array of links. Say you had a file called “graph.csv”:

    source,target
    A1,A2
    A2,A3
    A2,A4
    

    You could load this file using d3.csv and then produce an array of nodes and links:

    d3.csv("graph.csv", function(links) {
      var nodesByName = {};
    
      // Create nodes for each unique source and target.
      links.forEach(function(link) {
        link.source = nodeByName(link.source);
        link.target = nodeByName(link.target);
      });
    
      // Extract the array of nodes from the map by name.
      var nodes = d3.values(nodeByName);
    
      function nodeByName(name) {
        return nodesByName[name] || (nodesByName[name] = {name: name});
      }
    });
    

    You can then pass these nodes and links to the force layout to visualize the graph:

    • http://bl.ocks.org/2949937

    If you want to produce a tree instead, then you’ll need to do a slightly different form of data transformation to accumulate the child nodes for each parent.

    d3.csv("graph.csv", function(links) {
      var nodesByName = {};
    
      // Create nodes for each unique source and target.
      links.forEach(function(link) {
        var parent = link.source = nodeByName(link.source),
            child = link.target = nodeByName(link.target);
        if (parent.children) parent.children.push(child);
        else parent.children = [child];
      });
    
      // Extract the root node.
      var root = links[0].source;
    
      function nodeByName(name) {
        return nodesByName[name] || (nodesByName[name] = {name: name});
      }
    });
    

    Like so:

    • http://bl.ocks.org/2949981
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following: while($myRow = odbc_fetch_array( $result )){ <--lots of rows $thisResult['name'] =
While following path for wait system call, noticed that before calling do_wait_thread we get
I get an exception while executing following piece of code bool FieldValueMessage::Get(const std::string &field,
The C++ FAQ over at parashift uses something similar to the following: while (cout
I have a simple menu, something like the following: while(cmd != quit){ cin >>
while using the following constructor $this->pdo = new PDO ($this->source, $this->username, $this->password); if I
while executing the following query, i get an error that there's an error in
Consider the following code: while(true) { someFunction(); Thread.sleep(1000); } What I want is that,
I am getting the following error while compiling a sample program in Qt 4.5
I am getting the following error while running my MVC application, which uses the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.