D3.js
≈ 4 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
D3.js (also known as D3, short for Data-Driven Documents) is a JavaScript library for producing dynamic, interactive data visualizations in web browsers. It makes use of Scalable Vector Graphics (SVG), HTML5, and Cascading Style Sheets (CSS) standards. It is the successor to the earlier Protovis framework. Its development was noted in 20111, as version 2.0.0 was released in August 2011. With the release of version 4.0.0 in June 2016, D3 was changed from a single library into a collection of smaller, modular libraries that can be used independently.
D3.js (also known as D3, short for Data-Driven Documents) is a JavaScript library for producing dynamic, interactive data visualizations in web browsers. It makes use of Scalable Vector Graphics (SVG), HTML5, and Cascading Style Sheets (CSS) standards. It is the successor to the earlier Protovis framework. Its development was noted in 2011, as version 2.0.0 was released in August 2011. With the release of version 4.0.0 in June 2016, D3 was changed from a single library into a collection of smaller, modular libraries that can be used independently. d3.selectAll("p") // select all elements .style("color", "lavender") // set style "color" to value "lavender" .attr("class", "squares") // set attribute "class" to value "squares" .attr("x", 50); // set attribute "x" (horizontal position) to value 50px The selection can be based on an HTML tag, class, identifier, attribute, or place in the hierarchy. Once elements are selected, one can apply operations to them. This includes getting and setting attributes, display texts, and styles (as in the above example). Elements may also be added and removed. This process of modifying, creating and removing HTML elements can be made dependent on data, which is the basic concept of D3.js. d3.selectAll("p") // select all elements .transition("trans_1") // transition with name "trans_1" .delay(0) // transition starting 0ms after trigger .duration(500) // transitioning for 500ms .ease(d3.easeLinear) // transition easing progression is linear... .style("color", "pink"); // ... to color: pink // Data var countriesData = [ { name: "Ireland", income: 53000, life: 78, pop: 6378, color: "black" }, { name: "Norway", income: 73000, life: 87, pop: 5084, color: "blue" }, { name: "Tanzania", income: 27000, life: 50, pop: 3407, color: "grey" } ]; // Create SVG container var svg = d3.select("#hook").append("svg") .attr("width", 120) .attr("height", 120) .style("background-color", "#D0D0D0"); // Create SVG elements from data svg.selectAll("circle") // create virtual circle template .data(countriesData) // bind data .join("circle") // joins data to the selection and creates circle elements for each individual data .attr("id", function(d) { return d.name }) // set the circle's id according to the country name .attr("cx", function(d) { return d.income / 1000 }) // set the circle's horizontal position according to income .attr("cy", function(d) { return d.life }) // set the circle's vertical position according to life expectancy .attr("r", function(d) { return d.pop / 1000 * 2 }) // set the circle's radius according to country's population .attr("fill", function(d) { return d.color }); // set the circle's color according to country's color Generated SVG graphics are designed according to the provided data.
Community
D3.js is a popular toolset used by many individuals and organizations for data visualization. Some organizations that use it include The New York Times, Airbnb, and MTV. Mike Bostock created bl.ocks as a website for sharing D3 visualizations and code snippets, which used GitHub Gist to host the code. He later created Observable as a place where programmers could make and share visualizations. (Similar to bl.ocks but the code is all hosted on the observable site). There are also D3 communities on many programming sites like CodePen.
References
Related projects
The Vega and Vega-Lite visualisation grammars are a declarative visualization specification built on parts of D3.js.
External links
D3.js Gallery , search for blocks by methods used D3 "reusable chart" libraries: C3 https://c3js.org Plotly https://plot.ly/javascript bl.ock.org and blockbuilder.org: popular early gallery system. Observablehq.com : main D3js playground.
Text derived from https://en.wikipedia.org/w/index.php?oldid=1372698578 under CC BY-SA 4.0; modifications have been made.
References
- ↩Wikipedia “D3.js” release date (×1) · confidence 0.95 revision URL