Built with blockbuilder.org
This code will visualize data from a CSV via two objects: (1) a scatter plot of GF/GA with team code labels and (2) a mouseover that will tell additional details about the team data point
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
</style>
</head>
<body>
<script>
var dataset = [];
// Create SVG element
var svgW = 700;
var svgH = 700;
// Create SVG
var svg = d3.select("body").append("svg")
.attr("width", svgW)
.attr("height", svgH)
// Create data parsing function
var rowConverter = function (d) {
return {
Team: d.Team,
TeamCode: d.TeamCode,
Place: parseInt(d.Place),
Record: d.Record,
GF: parseInt(d.GF),
GA: parseInt(d.GA),
Pts: parseInt(d.Pts),
Notes: d.Notes
};
}
// Load Data and execute scatter
d3.csv("201617PL.csv", rowConverter, function (data) {
var dataset = data;
svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
.attr("x", 50)
.attr("y", function (d,i) {
return (i*20)+50; }
)
.text(function (d) {
return d.TeamCode + " - " + d.Place; }
);
});
svg.append("text")
.text("Edit the code below to change me!")
.attr("y", 200)
.attr("x", 120)
.attr("font-size", 36)
.attr("font-family", "monospace")
</script>
</body>
https://d3js.org/d3.v4.min.js