D3.js: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 57: Line 57:
* http://d3js.org/ - Short intro page with links to the above and the source code zip file.
* http://d3js.org/ - Short intro page with links to the above and the source code zip file.


=== Other ===
* http://bost.ocks.org/mike/join/
* [http://alignedleft.com/tutorials/d3/ D3 Tutorials] by Scott Murray (Original tutorial expanded into the book)


== Bibliography ==
== Bibliography ==

Revision as of 19:45, 24 April 2013

<pageby nominor="false" comments="false"/>

Draft

Introduction

“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)

Introductory D3 + SVG example

D3 perfectly works with HTML and CSS. However, we get more power from using SVG.

Live example:

Chaining

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");
Anonymous functions

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 );})


Links

Official

  • http://d3js.org/ - Short intro page with links to the above and the source code zip file.

Other

Bibliography

  • Michael Bostock, Vadim Ogievetsky and Jeffrey Heer (). D3 : Data-Driven Documents, IEEE Trans. Visualization & Comp. Graphics (Proc. InfoVis), 2011
  • Scott Murray (2013). Interactive Data Visualization for the Web. An Introduction to Designing with D3. O'Reilly Media