A simple bar chart of tornadic activity in the state of Oklahoma since 1990. This is a simple bar chart showing the total number of tornadoes. I'll be fixing the text issues and creating a stacked bar version shortly. This is a D3 version of this chart published for Oklahoma Watch.
xxxxxxxxxx
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.bar {
fill: steelblue;
}
.bar text {
color: #000000;
}
.x.axis path {
display: none;
}
div.tooltip {
position: absolute;
text-align: left;
padding: 2px;
font: 12px sans-serif;
background: #EDEDED;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
</style>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var div = d3.select("body").append("div").attr("class", "tooltip").style("opacity", 0);
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var svg = d3.select("body").append("svg")
.attr("class", "chart")
.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("tornado90-13.csv", function(error, data) {
data.forEach(function(d) {
d.total = +d.total
d.year = +d.year;
});
x.domain(data.map(function(d) { return d.year; }));
y.domain([0, d3.max(data, function(d) { return d.total; })]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Tornado count");
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.year); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.total); })
.attr("height", function(d) { return height - y(d.total); })
.on("mouseover", function (d) {
div.transition()
.duration(1000)
.style("opacity", .9);
div.html(
"<table>"
+"<tr><th>Year</th> <th>Total</th></tr>"
+ "<tr><td>" + d.year + ":</td><td>" + d.total + "</td></tr>"
+ "</table>")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY-20) + "px")
})
.on("mouseout", function (d){
div.transition()
.duration(500)
.style("opacity", 0);
});
});
</script>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js