framework focus on efficient manipulation of documents based on data bind arbitrary data to the DOM apply data-driven transformations to the document functional/declarative style support for interaction and animation you have to do the graphical representation yourself! but has helpers for SVG generation from Intro to d3
functions to styles, attributes and other properties a lot of built-in reusable functions available bound data available as first argument you can omit the data operator the second time! d3.selectAll("p") .data([4, 8, 15, 16, 23, 42]) .style("font-size", function(d, i) { return d + "px"; });
elements without a DOM representation exit: selects all DOM elements without data common pattern perform only necessary modifications var p = d3.select("body").selectAll("p") // Update… .data([4, 8, 15, 16, 23, 42]) .text(String); p.enter().append("p") // Enter… .text(String); p.exit().remove(); // Exit…
existing selection maintains the hierarchical structure d3.selectAll("ul") .data(questions) // an array of questions .selectAll("li") // a nested array of responses .data(function(d) { return d.responses; } ) // the text of the response .text(function(d) { return d.text; });
interpolation of basic types, numbers and numbers in strings (e.g. "15px") // fade background from white to black in 1s d3.select("body").transition() .duration(1000) .style("background-color", "black");
<script type="text/javascript" src="d 3/d3.v3.js"></script> </head> <body> <script type="text/javascript"> // Your beautiful D3 code will go here </script> </body> </html>
ata based on year. svg.transition() .duration(duration) .ease("linear") .tween("year", tweenYear()) .each("end", enableInteraction); // Tweens the entire chart by first tweening the year, and then the data. // For the interpolated data, the dots and la bel are redrawn. function tweenYear(start, end) { start = start || 1800; end = end || 2009; return function() { var year = d3.interpolateNumber(start, en d); return function(t) { displayYear(year(t)) ; }; } }