Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2012 08:00
Show Gist options
  • Save anonymous/4174418 to your computer and use it in GitHub Desktop.
Save anonymous/4174418 to your computer and use it in GitHub Desktop.
Another Inlet
{"description":"Another Inlet","endpoint":"","display":"svg","public":true,"require":[],"tab":"edit","display_percent":0.7,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.time.scale()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
.x(function(d) { return x(d.clock); })
.y(function(d) { return y(d.value); });
var svg = d3.select("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var data = [{"itemid":"25540","clock":"1352815031","value":"0","ns":"105476610"},{"itemid":"25540","clock":"1352815110","value":"1","ns":"565450140"},{"itemid":"25540","clock":"1352815928","value":"0","ns":"454306637"},{"itemid":"25540","clock":"1352815997","value":"1","ns":"882903296"},{"itemid":"25540","clock":"1352816048","value":"0","ns":"849691092"},{"itemid":"25540","clock":"1352816072","value":"1","ns":"126641584"},{"itemid":"25540","clock":"1352816424","value":"0","ns":"484529767"},{"itemid":"25540","clock":"1352816520","value":"1","ns":"399337388"},{"itemid":"25540","clock":"1352816988","value":"0","ns":"741789085"},{"itemid":"25540","clock":"1352817091","value":"1","ns":"881805330"}];
data.forEach(function(d){
// console.log("d.clock: " + d.clock);
// console.log("d.value: " + d.value);
d.date = new Date(d.clock * 1000);
d.close = d.value;
// console.log("d.date: " + d.date);
// console.log("d.close: " + d.close);
});
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain(d3.extent(data, function(d) { return d.close; }));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 5)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Value");
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment