Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to D3.js

Introduction to D3.js

Avatar for Philip Davis

Philip Davis

June 21, 2014

More Decks by Philip Davis

Other Decks in Technology

Transcript

  1. Outline  Web Standards  Getting setup with the library

     Binding data to documents  Data loading  Mini project  Resources
  2. The Library “D3 solves the crux of the problem: efficient

    manipulation of documents based on data. This avoids proprietary representation and affords extraordinary flexibility” Mike Bostock
  3. Enter, Update, and Exit .enter().append(“circle”); Only 3 possible scenarios. 

    ENTER: Data elements > SVG elements  EXIT: Data elements < SVG elements  UPDATE: Data elements = SVG elements .exit().remove();
  4. Attributes Your rendered elements should reflect the data in some

    way.  Color  Position  Size  Stroke  CSS classes .attr(“fill”, “#FF0000”) .attr(“x”, 20) .attr(“width”, 100) .attr(“stroke”, “red”) .attr(“class”, “.red”)
  5. Putting it Together var circle = svg.selectAll("circle") .data([1,2,3]) .enter() .append("circle")

    .attr("r", 10) .attr("cx", 10) .attr("cy", 10) .attr("fill", "green");