D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG and CSS [...]d3js.org
function chart() {
// generate chart here
}
A function; the standard unit of code reuse!-- Mike Bostock, Towards Reusable Charts
var bar = d3.select("svg g").selectAll("rect.bar")
.data(data);
bar.enter().append("rect")
.classed("bar", true);
.attr("height", function(d) { return d * 20; });
.attr("width", 0)
.transition()
.duration(1000)
.attr("width", 100);
bar.transition()
.duration(1000)
.attr("x", function(d, i) { return i * 100; });
bar.exit().transition().duration(1000)
.attr("width", 0)
.remove();
var layer = d3.select("svg g").layer({
dataBind: function(data) {
return this.selectAll("rect.bar").data(data);
},
insert: function() {
return this.append("rect").classed("bar", true);
},
events: {
enter: function() {
this.attr("height", function(d) { return d * 20; })
.attr("width", 0);
},
"enter:transition": function() {
this.duration(1000).attr("width", 100);
},
"update:transition": function() {
this.duration(1000)
.attr("x", function(d, i) { return i * 100; });
},
"exit:transition": function() {
this.duration(1000)
.attr("width", 0)
.remove();
}
}
});
layer.draw(data);
layer.on("enter", function() {
this.attr("width", 100)
.style("opacity", 0);
});
layer.on("enter:transition", function() {
this.style("opacity", 1);
});
layer.on("exit:transition", function() {
this.attr("width", 100)
.style("opacity", 0);
});
d3.chart("Homme", {
initialize: function() {
this.layer("barLayer", this.base.append("g"), {
// layer options: insert, databind, events
});
}
});
var myChart = d3.select("svg").chart("Joshua");
myChart.draw(data);
d3.chart("Jones", {
transform: function(data) {
return d3.layout.chord()
.padding(.05)
.sortSubgroups(d3.descending)
.matrix(data);
}
});
d3.chart("Drummer", {
// chart options: initialize, transform, etc...
});
d3.chart("Drummer").extend("Grohl", {
// chart options: initialize, transform, etc...
});
d3.chart("TCV", {
initialize: function() {
this.mixin("Homme", this.base.append("g"), {
// chart options: initialize, transform, etc...
});
this.mixin("Grohl", this.base.append("g"), {
// chart options: initialize, transform, etc...
});
}
});
d3.chart("Jones", {
initialize: function() {
var chart = this;
// ...
barLayer.on("enter", function() {
this.on("mouseover", function() {
chart.trigger("brush:bar", arguments);
});
});
});
d3.chart("Billy", {
dataAttrs: ["value"],
initialize: function() {
// ...
this.barLayer.on("enter", function() {
this.attr("height", function(d) {
return d.value;
});
});
}
});
var myChart = d3.select("svg").chart("Billy", {
dataMapping: {
value: function() {
return this.VALUE;
}
}
});
myChart.draw([ { VALUE: 23 } ]);
this.transition()
.transition()
.transition().text("Sharing");
<path>
and d3.layout
supportUse a spacebar or arrow keys to navigate