Built with blockbuilder.org
A D3 version of the graph which appeared in this blog post: https://westlondonzone.org/myvoice2017update/
xxxxxxxxxx
<Doctype html>
<style>
.axis path,
.axis line {
fill: none;
stroke: #D4D8DA;
stroke-width: 1px;
shape-rendering: crispEdges;
}
.x path {
display: none;
}
.toolTip {
position: absolute;
display: none;
max-width: 200px;
height: auto;
background: white;
border-radius: 20px;
padding: 14px;
border: 1px solid #777777;
text-align: center;
font-family: sans-serif
}
p {
color: #3f3f3f;
font-size: 20px;
line-height: 24px;
font-weight: 300;
margin-top: 20px;
margin-bottom: 20px;
}
body {
font-family: 'PT Sans', sans-serif;
color: #3f3f3f;
margin-left: 100px;
margin-right: 100px;
font-size: 16px;
font-weight: 300;
}
#tooltip.hidden {
display: none;
}
.legend {
font-size: 12px;
}
rect {
stroke-width: 2;
}
</style>
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<svg width="960" height="500"></svg>
<script>
var svg = d3.select("svg"),
margin = {top: 10, right: 100, bottom: 30, left: 150},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom;
var tooltip = d3.select("body").append("div").attr("class", "toolTip");
var x = d3.scaleLinear().range([0, width]);
var y = d3.scaleBand().range([height, 0]);
var g = svg.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var color = d3.scaleOrdinal()
.range(["#99CC00"]);
d3.csv("Data.csv", function(error, data) {
if (error) throw error;
data.forEach(function(d) {
d.Total = +d.Total;
});
x.domain([0, d3.max(data, function(d) { return d.Total; })]);
y.domain(data.map(function(d) { return d.Risk; })).padding(0.1);
g.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")");
g.append("g")
.attr("class", "y axis")
.style("font-size", "15px")
.call(d3.axisLeft(y));
g.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", 0)
.attr("height", y.bandwidth())
.attr("y", function(d) { return y(d.Risk); })
.attr("width", function(d) { return x(d.Total); })
.attr("fill", function(d) { return color(d.Domain); })
.on("mouseover", function(d){
tooltip
.style("left", d3.event.pageX - 50 + "px")
.style("top", d3.event.pageY - 25 + "px")
.style("display", "inline-block")
.html("<b>" + d.Total + " students at risk" + "</b>" + "<br>" +
"<br>" +
"<i>" + d.Risk +": " + "</i>" +
"<br>" +
d.Description);
})
.on("mouseout", function(d){ tooltip.style("display", "none");});
});
</script>
</body>
https://d3js.org/d3.v4.min.js