Created
November 28, 2012 17:26
-
-
Save mccannf/4162693 to your computer and use it in GitHub Desktop.
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
[ | |
{ | |
"result": 10, | |
"finished_at": "2011-12-01" }, | |
{ | |
"result": 20, | |
"finished_at": "2011-12-03" }, | |
{ | |
"result": 30, | |
"finished_at": "2011-12-05" }, | |
{ | |
"result": 40, | |
"finished_at": "2011-12-07" }, | |
{ | |
"result": 50, | |
"finished_at": "2011-12-09" }, | |
{ | |
"result": 60, | |
"finished_at": "2011-12-11" }, | |
{ | |
"result": 70, | |
"finished_at": "2011-12-13" } | |
] |
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> | |
body { | |
font: 10px sans-serif; | |
} | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
.x.axis path { | |
display: none; | |
} | |
.line { | |
fill: none; | |
stroke: steelblue; | |
stroke-width: 1.5px; | |
} | |
</style> | |
<body> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/2.10.0/d3.v2.min.js"></script> | |
Gist for this is at: <a href="https://gist.github.com/gists/4162693/">https://gist.github.com/gists/4162693/</a> | |
<script> | |
d3.json("builds.json", function(data){ | |
var format = d3.time.format("%Y-%m-%d"); | |
console.log("Data goes here:"+data); | |
data.forEach(function(d) { | |
d.finished_at = format.parse(d.finished_at); | |
}); | |
var margin = {top: 40, right: 40, bottom: 40, left: 40}, | |
width = 960, | |
height = 500; | |
var x = d3.time.scale() | |
.domain(d3.extent(data, function(d) { return d.finished_at; })) | |
.range([0, width - margin.right - margin.left]); | |
var y = d3.scale.linear() | |
.domain(d3.extent(data, function(d) { return d.result; })) | |
.range([height - margin.top - margin.bottom, 0]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom"); | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient("left"); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
svg.selectAll("circle") | |
.data(data) | |
.enter().append("circle") | |
.attr("cx", function(d) { return x(d.finished_at); }) | |
.attr("cy", function(d) { return y(d.result); }) | |
.attr("r", 6); | |
svg.append("g") // Render the axis by calling a <g> selection. | |
.attr("transform", "translate(0," + y.range()[0] + ")") //setzt x-achse an null punkt von y-achse | |
.call(xAxis); | |
svg.append("g") | |
.call(yAxis); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment