From Edutechwiki - Reading time: 2 min“D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.” (d3js.org, April 2013)
If you want a quick introduction with a few slides, you can see a Macwright presentation about D3.
But as stated in the presentatino, keep in mind that "d3 requires deep proficiency in javascript".
D3 perfectly works with HTML and CSS. However, we get more power from using SVG.
Live example:
D3 implements a chaining mechanism using the CSS W3C Selectors API. Read a chain from right to left or bottom to top. The following are equivalent:
// take 1
d3.selectAll("p").style("color", "white");
// take 2
d3
.selectAll("p")
.style("color", "white");
The following just returns the value it is given.
function(d) {
return d;
}
The following code would take the value of the currently selected data element (i.e. one of [50, 100, 150, 200, 250] and insert it into the the "text" child of the current DOM element. “Computed properties often refer to bound data. Data is specified as an array of values, and each value is passed as the first argument (d) to selection functions.” (d3js.org).
.text(function(d) {return d;});
The following code defines a function that will be given both the value of the currently selected data element and its position.
.attr("cx", function(d, i) {return 25 + (i * 50 + i * d * 0.1 );})