Displaying a tree
In this recipe, we will take a look into how to display data in a tree-like layout. We are going to visualize a small family tree of Linux represented via JSON file. Additionally, will be using the D3.js
file for manipulating the DOM to display the data.
Getting ready
First, we need to have the data that is going to be used for the visualization. We need to get the tree.json
file that is part of the examples for this recipe.
How to do it...
We will write the HTML and the backing JavaScript code that should generate data from a JSON file:
Let's first take a look a the structure of the JSON data:
{ "name": "GNU/Linux", "url": "http://en.wikipedia.org/wiki/Linux", "children": [ { "name": "Red Hat", "url": "http://www.redhat.com", "children": [ .. ] } ] ... }
Each object has a
name
attribute representing the distribution name, aurl
attribute that has a link to the official web page, and the optionalchildren
attribute that can contain a list of other...