Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created September 5, 2016 19:36
Show Gist options
  • Save ramnathv/92253ca053bdab15677af521fce5cf82 to your computer and use it in GitHub Desktop.
Save ramnathv/92253ca053bdab15677af521fce5cf82 to your computer and use it in GitHub Desktop.
D3 Bar Chart
<div class="chart"></div>
const data = [4, 8, 15, 16, 23, 42];
const x = d3.scale.linear()
.domain([0, d3.max(data)])
.range([0, 420]);
d3.select(".chart")
.selectAll("div")
.data(data)
.enter().append("div")
.style("width", d => x(d) + "px")
.text(d => d + 1);
<script src="https://d3js.org/d3.v3.min.js"></script>
.chart div {
font: 10px sans-serif;
background-color: steelblue;
text-align: right;
padding: 3px;
margin: 1px;
color: white;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment