Skip to content

Instantly share code, notes, and snippets.

@martzcodes
Last active Aug 29, 2015
Embed
What would you like to do?
/* data=
[
{
"name":"asdf",
"values":[{"date":1398206589000,"temperature":94.9},{"date":1398206592000,"temperature":63.9},{"date":1398206595000,"temperature":77.6},{"date":1398206598000,"temperature":46.8}]
},{
"name":"sensor 2",
"values":[{"date":1398206589000,"temperature":82.8},{"date":1398206592000,"temperature":99.5},{"date":1398206595000,"temperature":5.6},{"date":1398206598000,"temperature":65.3},{"date":1398206601000,"temperature":35.5},{"date":1398206604000,"temperature":65.6},{"date":1398206607000,"temperature":24.1},{"date":1398206610000,"temperature":72.4},{"date":1398206613000,"temperature":35.5},{"date":1398206616000,"temperature":21.2},{"date":1398206619000,"temperature":46.6},{"date":1398206622000,"temperature":13.5},{"date":1398206625000,"temperature":99.7},{"date":1398206628000,"temperature":2.5},{"date":1398206631000,"temperature":73.3},{"date":1398206634000,"temperature":3.8},{"date":1398206637000,"temperature":3},{"date":1398206640000,"temperature":75.4},{"date":1398206643000,"temperature":41.4},{"date":1398206646000,"temperature":79.3},{"date":1398206649000,"temperature":96.2},{"date":1398206652000,"temperature":40.3},{"date":1398206655000,"temperature":71.1},{"date":1398206658000,"temperature":92.1}]
}
]
*/
var hackyFill = function(d,i) {
for (var j = 0; j < data.length; j++) {
if (data[j].values[i].date == d.date && data[j].values[i].temperature == d.temperature) {
return color(data[j].name);
}
}
}
var sensor = svg.selectAll(".sensor")
.data(data)
.enter().append("g")
.attr("class", "sensor");
sensor.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.name); });
sensor.selectAll("circle")
.data(function(d) {return d.values;})
.enter().append("circle")
.attr("class","dot")
.attr("r", 3.5)
.attr("cx", function(d) { return x(d.date); })
.attr("cy", function(d) { return y(d.temperature); })
.style("fill", function(d,i) { return hackyFill(d,i);});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment