Response to a question on stackoverflow
Created
March 24, 2013 17:00
-
-
Save AndrewStaroscik/5232640 to your computer and use it in GitHub Desktop.
calling a line function on information nested in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.visline { | |
stroke: #000; | |
fill: none; | |
shape-rendering: crispEdges; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var margin = {top: 20, right: 40, bottom: 20, left: 40}; | |
var width = 780 - margin.left - margin.right, | |
height = 250 - margin.top - margin.bottom; | |
var data = [ | |
{ | |
key: "kmm03", | |
value:[ | |
{"time":1364108443000,"mesure":"1.6299999952316284"}, | |
{"time":1364108503000,"mesure":"1.100000023841858"}, | |
{"time":1364108563000,"mesure":"1.159999966621399"} | |
] | |
}, | |
{ | |
key: "kmm04", | |
value:[ | |
{"time":1364108416000,"mesure":"2.690000057220459"}, | |
{"time":1364108476000,"mesure":"3.319999933242798"}, | |
{"time":1364108536000,"mesure":"3.140000104904175"}, | |
{"time":1364108596000,"mesure":"2.9800000190734863"} | |
] | |
} | |
]; | |
var time_scale = d3.time.scale() | |
//.domain(time_extent) | |
.domain([1364108443000, 1364112559000]) | |
.range([0, width]); | |
var mesure_scale = d3.scale.linear() | |
.domain([0,10]) | |
.range([height, 0]); | |
var vis = d3.select("body") | |
.append("svg:svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
var time_axis = d3.svg.axis() | |
.scale(time_scale) | |
.orient("bottom"); | |
var mesure_axis = d3.svg.axis() | |
.scale(mesure_scale) | |
.orient("left"); | |
var set_axis_t = vis.append("svg:g") | |
.attr("transform", "translate(0, " + height +")") | |
.call(time_axis); | |
var set_axis_m = vis.append("svg:g") | |
.attr("transform", "translate(0, 0)") | |
.call(mesure_axis); | |
var line = d3.svg.line() | |
.x(function(d){return time_scale(d.time);}) | |
.y(function(d){return mesure_scale(d.mesure);}); | |
var group = vis.selectAll('.visline') | |
.data(data) | |
.enter().append('path') | |
.attr('class', 'visline') | |
.attr("d", function(d) {return line(d.value);}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment