Skip to content

Instantly share code, notes, and snippets.

@jtr13
Last active December 11, 2019 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtr13/618a9ad4e7809c64182a186a04746717 to your computer and use it in GitHub Desktop.
Save jtr13/618a9ad4e7809c64182a186a04746717 to your computer and use it in GitHub Desktop.
d3.csv
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v5.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
const w = 500;
const h = 400;
const svg = d3.select("body").append("svg").attr("width", w).attr("height", h);
const xScale = d3.scaleLinear().domain([0,1]).range([0,w]);
const yScale = d3.scaleLinear().domain([0,1]).range([h,0]);
const rowConverter = function(d) {
return {grad: +d.graduation_rate,
attend: +d.attendance_rate}
};
// Feel free to change or delete any of the code you see in this editor!
d3.csv("https://data.cityofnewyork.us/api/views/uq7m-95z8/rows.csv", rowConverter).then(function (data) {
console.log(data)
svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr("cx", d => xScale(d.grad))
.attr("cy", d => yScale(d.attend))
.attr("r", "3")
.attr("fill", "red");
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment