Skip to content

Instantly share code, notes, and snippets.

@crstn
Last active March 15, 2021 10:31
Show Gist options
  • Save crstn/7806bf541c6ea1394e506c895ee29b85 to your computer and use it in GitHub Desktop.
Save crstn/7806bf541c6ea1394e506c895ee29b85 to your computer and use it in GitHub Desktop.
Examples for GeoViz lecture, borrowed from http://maptimeboston.github.io/d3-maptime/
<html>
<head>
<title>A D3 chart</title>
<script src="http://d3js.org/d3.v6.min.js" charset="utf-8"></script>
</head>
<body>
<script>
var ratData = [400, 900, 300, 600]; // looks familiar!
var svg = d3.select("body")
.append("svg")
.attr("width", 500)
.attr("height", 150);
svg.selectAll("rect")
.data(ratData)
.enter()
.append("rect")
.attr("x", function(d, i) {
return i * 25;
})
.attr("width", 15)
.attr("fill", "#d1c9b8")
.attr("height", function(d) {
return d / 10 * 1.5;
})
.attr("y", function(d) {
return 150 - d / 10 * 1.5;
});
</script>
</body>
</html>
<html>
<head>
<title>A D3 chart</title>
<script src="http://d3js.org/d3.v6.min.js" charset="utf-8"></script>
</head>
<body>
<svg width="100" height="150">
<rect x="0" width="15" fill="#d1c9b8"></rect>
<rect x="25" width="15" fill="#d1c9b8"></rect>
<rect x="50" width="15" fill="#d1c9b8"></rect>
<rect x="75" width="15" fill="#d1c9b8"></rect>
</svg>
<script>
var ratData = [400, 900, 300, 600];
d3.selectAll("rect")
.data(ratData)
.attr("height", function(d) {
return d / 10 * 1.5;
})
.attr("y", function(d) {
return 150 - d / 10 * 1.5;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment