Skip to content

Instantly share code, notes, and snippets.

@js418
Last active February 24, 2017 17:25
Show Gist options
  • Save js418/3f71bbd9b2c647a885d76789ffac7d1d to your computer and use it in GitHub Desktop.
Save js418/3f71bbd9b2c647a885d76789ffac7d1d to your computer and use it in GitHub Desktop.
test
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
var svg = d3.select("body").append("svg")
.attr("width",800)
.attr("height",400),
margin = {top: 30, right: 20, bottom: 30, left: 20},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var x1 = d3.scaleBand()
.range([0,width])
.paddingInner(0.2)
.align(0.1);
var x2 = d3.scaleBand()
.range([0,width])
.paddingInner(0.2);
var x3 = d3.scaleBand()
.range([0,width])
.paddingInner(0.2);
var y1 = d3.scaleLinear()
.range([height,0])
var y2 = d3.scaleLinear()
.range([height,0])
var y3 = d3.scaleLinear()
.range([height,0])
d3.csv("test.csv",type, function(d){
x1.domain([0,10])
y1.domain([0,d3.max(d, function(d){return d.one;})])
g.selectAll("text")
.data(d)
.enter()
.append("rect")
.attr("x", function(d,i){
return i*20 + 30;
})
.attr("y", function(d){return height - y1(d.one);})
.attr("width", 10)
.attr("height", function(d){return y1(d.one);})
});
function type(d){
d.one = +d.one;
d.two = +d.two;
d.three = +d.three;
return d;
};
</script>
</body>
one two three
79 74 73
5 34 9
64 79 20
2 3 80
32 50 75
62 46 72
24 26 15
39 85 24
57 55 2
90 24 84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment