Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.v3.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.v3.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
You can’t perform that action at this time.