WOT - No of Chars (variation 2)

in response to http://stackoverflow.com/questions/21095910/d3-bar-chart-formation

by Nivaldo

HTML

<script src="http://mbostock.github.com/d3/d3.js"></script>
<div id="chart"></div>

CSS

.axis text {
  font: 10px sans-serif;
}
  
.axis path, .axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

JavaScript

var data = [[1,"Pr"],
    [6,"1"],
    [7,"2"],
    [4,"3"],
    [1,"4"],
    [0,"5"],
    [0,"6"],
    [2,"7"],
    [2,"8"],
    [2,"9"],
    [0,"10"],
    [1,"11"],
    [0,"12"],
    [6,"13"],
    [4,"14"],
    [4,"15"],
    [2,"16"],
    [3,"17"],
    [0,"18"],
    [0,"19"],
    [0,"20"],
    [0,"21"],
    [0,"22"],
    [0,"23"],
    [1,"24"],
    [1,"25"],
    [1,"26"],
    [0,"27"],
    [0,"28"],
    [0,"29"],
    [4,"30"],
    [4,"31"],
    [4,"32"],
    [9,"33"],
    [2,"34"],
    [1,"35"],
    [0,"36"],
    [0,"37"],
    [0,"38"],
    [2,"39"],
    [6,"40"],
    [1,"41"],
    [0,"42"],
    [0,"43"],
    [0,"44"],
    [0,"45"],
    [1,"46"],
    [6,"47"],
    [0,"48"],
    [0,"49"],
    [0,"50"],
    [2,"51"],
    [0,"52"],
    [0,"53"]];

var margin = {top: 10, right: 10, bottom: 30, left: 30},
    width = 900 - margin.left - margin.right,
    height = 140 - margin.top - margin.bottom;

var x = d3.scale.ordinal()
    .domain(data.map(function (d) {return +d[1]; }))
    .rangeRoundBands([margin.left, width], 0.05);

var y = d3.scale.linear()
     .domain([0, d3.max(data, function(d) { return d[0]; })])
     .range([height, 0]);

var xAxis = d3.svg.axis()
    .scale(x)
    .orient("bottom");

var yAxis = d3.svg.axis()
    .scale(y)
    .ticks(5)
    .orient("left");

var svg = d3.select("#chart").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(-30," + height + ")")
    .call(xAxis)
    .style("fill","gray")
.append("text")
    .attr("x", width)
    .attr("dy", 28)
    .attr("text-anchor", "end")
    .text("(Chapter)");

svg.append("g")
    .attr("class", "y axis")
    .call(yAxis)
    .style("fill","gray")
.append("text")
    .attr("transform", "rotate(-90)")
    .attr("y", 6)
    .attr("dy", ".71em")
   ...