Built with blockbuilder.org
xxxxxxxxxx
<meta charset="utf-8">
<head>
<style>
.axis {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
</style>
</head>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 40, left: 40},
width = 1020 - margin.left - margin.right,
height = 560 - margin.top - margin.bottom;
var x = d3.scale.linear().range([width, 0]);
var y = d3.scale.linear().range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(5);
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(10);
var svg = d3.select("body").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 + ")");
d3.csv("alpha_frequencies.csv", function(error, dataset) {console.log(dataset);
dataset.forEach(function(d) {
d.frequency = +d.frequency; //parseFloat(d.frequency)
d.letter = d.letter
});
x.domain(dataset.map(function(d) { return d.letter; }));
y.domain([0, d3.max(dataset, function(d) { return d.frequency; })]);
dataset.sort(function(a, b) {
return b.frequency - a.frequency;
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-01em")
.attr("dy", "-.55em")
.attr("transform", "rotate(-90)" );
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y",1)
.attr("dy", "-34")
.style("text-anchor", "end")
.text("Alpha Freq.");
svg.selectAll("rect")
.data(dataset)
.enter().append("rect")
.style("fill", "red")
.style("opacity", .0)
.transition()
.delay(function(d, i) { return i * 2000/(i+1*4) })
.duration(1000)
.style("opacity", 0.9)
.attr("x", function(d, i) { return i * width/26})
.attr("width", 35)
.attr("y", function(d) { return y(d.frequency); })
.attr("height", function(d) { return height - y(d.frequency);})
.transition()
.delay(2900)
.style("fill", "blue")
.style("opacity", 0.7)
.attr("height", 8)
// .remove();
});
</script>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js