Skip to content

Instantly share code, notes, and snippets.

@higgyCodes
Last active August 19, 2016 18:44
Show Gist options
  • Select an option

  • Save higgyCodes/1ff40b27c9f431ca3f01d08b171b1ccb to your computer and use it in GitHub Desktop.

Select an option

Save higgyCodes/1ff40b27c9f431ca3f01d08b171b1ccb to your computer and use it in GitHub Desktop.
Bar Chart
{"description":"Bar Chart","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"babel.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data.tsv":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":true,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/V8XYWiB.png"}
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 2 in line 1.
data.tsv#
letter frequency
A .08167
B .01492
C .02782
D .04253
E .12702
F .02288
G .02015
H .06094
I .06966
J .00153
K .00772
L .04025
M .02406
N .06749
O .07507
P .01929
Q .00095
R .05987
S .06327
T .09056
U .02758
V .00978
W .02360
X .00150
Y .01974
Z .00074
var dataset = [ 5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];
var w = 500;
var h = 100;
var barPadding = 0.3
svg = d3.select("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr ("x", function (d, i) {
return i * (w/ dataset.length - barPadding)
})
.attr("y", function(d) {return h - d})
.attr("width", 20)
.attr("height", function(d){
return d
})
.append("rect")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment