Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kristw
Last active July 24, 2020 21:25
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 kristw/ab3baa4b3b2725b3122ff179fdd7a8ab to your computer and use it in GitHub Desktop.
Save kristw/ab3baa4b3b2725b3122ff179fdd7a8ab to your computer and use it in GitHub Desktop.
blog example: d3
const x = d3.scaleBand().rangeRound([0, width]);
const y = d3.scaleLinear().range([height, 0]);
const svg = d3.select("svg").attr("width", width).attr("height", height);
x.domain(data.map(d => d.date));
y.domain([0, d3.max(data, d => d.value)]);
svg.selectAll("bar")
.data(data)
.enter().append("rect")
.style("fill", "steelblue")
.attr("x", d => x(d.date))
.attr("width", x.band())
.attr("y", d => y(d.value))
.attr("height", d => (height - y(d.value)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment