xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exercise 2: Free lunch</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
body {
background-color: lightcyan;
}
svg {
background-color: white;
}
p {
color: black;
font-family: Helvetica, sans-serif;
font-size: 16px;
}
h1 {
color: black;
font-family: Helvetica, sans-serif;
font-size: 22px;
}
rect:hover{
fill: dodgerblue;
}
</style>
</head>
<body>
<h1>STUDENTS WHO QUALIFY FOR FREE LUNCH</h1>
<p>The percentage of students qualifying for free lunch in Palm Beach County public schools is higher now than at any time during the past 20 years.</style></p>
<script type="text/javascript">
var svg = d3.select("body")
.append("svg")
.attr("width", 300)
.attr("height", 440)
.attr("fill", "blue");
d3.csv("FRlunchdata.csv", function(data) {
data.sort(function(a, b) {
return d3.ascending(a.YEAR, b.YEAR);
});
var rects = svg.selectAll("rect")
.data(data)
.enter()
.append("rect");
rects.attr("x", 0)
.attr("y", function(d, i) {
return i * 20;
})
.attr("width", function(d) {
return d.Percentfreelunch * 3;
})
.attr("height", 19)
.append("title")
.text(function(d) {
return d.Percentfreelunch + "% of students qualified for free lunch in " + d.YEAR;
});
svg.selectAll("text")
.data(data)
.enter()
.append("text")
.text(function(d) {
return d.YEAR;
})
.attr("x", 5)
.attr("y", function(d, i) {
return i * 20 + 14;
})
.attr("font-family", "sans-serif")
.attr("font-size", "12px")
.attr("fill", "white");
});
</script>
</body>
</html>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js