Skip to content

Instantly share code, notes, and snippets.

@ffaerber
Last active August 29, 2015 14:07
Show Gist options
  • Save ffaerber/9702776ffc3767422401 to your computer and use it in GitHub Desktop.
Save ffaerber/9702776ffc3767422401 to your computer and use it in GitHub Desktop.
numbers = [5, 3, 23, 6, 7, 0, 1, 25, 11, 19, 20]
chartHeight = 300
chart = d3.select("body")
.append("svg")
.attr("width", "100%")
.attr("height", "100%")
bars = chart.selectAll("g.bar").data(numbers).enter()
.append("g")
.attr("class", "bar")
bars.append("rect")
.attr("y", (d) -> chartHeight - d * 10)
.attr("x", (d, i) -> i * 20)
.attr("width", 20)
.attr("height", (d) -> d * 10)
bars.append("line")
.attr("class", "budget")
.attr("y1", (d) -> chartHeight - d * 9)
.attr("y2", (d) -> chartHeight - d * 9)
.attr("x1", (d, i) -> i * 20)
.attr("x2", (d, i) -> i * 20 + 20)
.attr("stroke", (d) -> if d < 20 then "white" else "#aaa")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment