Skip to content

Instantly share code, notes, and snippets.

@nerik
Created December 7, 2016 16:04
Show Gist options
  • Save nerik/5c59af6b4cdc8369d8af3cd796cef38b to your computer and use it in GitHub Desktop.
Save nerik/5c59af6b4cdc8369d8af3cd796cef38b to your computer and use it in GitHub Desktop.
Quick histograms in the browser console with d3
const bins = d3.histogram()(data);
const x = d3.scaleLinear().domain([0, d3.max(bins, d => d.length)]).range([0, 30]);
console.table(bins.filter(bin => bin.length).map(bin => {
const binMin = d3.min(bin).toLocaleString();
const binMax = d3.max(bin).toLocaleString();
return {
range: [binMin, binMax].join('-'),
bars: Array(Math.round(x(bin.length))).join('█'),
num: bin.length
};
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment