This example is out-of-date; I prefer this newer histogram example that places the tick marks between bars. However, the implementation still stands as an example of the reusable chart module pattern.
xxxxxxxxxx
<meta charset="utf-8">
<style>
.bars rect {
fill: steelblue;
}
.axis text {
font: 10px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="histogram-chart.js"></script>
<script>
d3.select("body")
.datum(irwinHallDistribution(10000, 10))
.call(histogramChart()
.bins(d3.scale.linear().ticks(20))
.tickFormat(d3.format(".02f")));
function irwinHallDistribution(n, m) {
var distribution = [];
for (var i = 0; i < n; i++) {
for (var s = 0, j = 0; j < m; j++) {
s += Math.random();
}
distribution.push(s / m);
}
return distribution;
}
</script>
https://d3js.org/d3.v3.min.js