Skip to content

Instantly share code, notes, and snippets.

@Bill77
Last active August 29, 2015 14:10
Show Gist options
  • Save Bill77/5dddcf3cb396ec366edd to your computer and use it in GitHub Desktop.
Save Bill77/5dddcf3cb396ec366edd to your computer and use it in GitHub Desktop.
Line Graph Vis
{"description":"Line Graph Vis","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}},"fullscreen":false,"play":false,"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/iKr9ZOI.png"}
var svg = d3.select("svg")
var boundsHeight = 250;
var dataVals = [
{
times: [200,100,250],
bounds: 250,
x: 200
}, {
times: [200,100,250],
bounds:250,
x: 450
}, {
times: [200,100,250],
bounds: 250,
x: 700
}];
var xPos;
svg.selectAll("rect")
.data(dataVals).enter()
.append("rect").attr({
width: function(d) {return d.bounds;},
height: boundsHeight,
x: function(d) { return d.x; },
y: function(d, i) {return (i * boundsHeight)+75;},
fill: "#F2F2F2",
id: function(d,i) {return "Rect" + d + '_' + i;}
}).selectAll("line")
.data(function(d) {
xPos = d.x;
return d.times;
}).enter()
.append('line').attr({
x1:function(d) {return 200;},
y1:210,
x2:function(d) {return 200+d;},
y2:210,
stroke: "blue",
'stroke-width':"2",
name: function(d,i) {return "Line" + i + '_' + d}
});
svg.append("line").attr({
x1:250,
y1:250,
x2:300,
y2:300,
stroke: "blue",
'stroke-width':"2"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment