Built with blockbuilder.org
Last active
February 18, 2016 17:13
-
-
Save Wanagram/a4a5dbb278ba56f94d98 to your computer and use it in GitHub Desktop.
Ruler
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; | |
shape-rendering: crispEdges; | |
} | |
.grid-background { | |
fill: #ddd; | |
} | |
.grid line { | |
stroke: #000000; | |
} | |
.grid .minor line { | |
stroke-opacity: .5; | |
} | |
.grid text { | |
display: none; | |
} | |
.axis line { | |
stroke: #000; | |
} | |
.axis path, | |
.grid path { | |
display: none; | |
} | |
.axis text { | |
display: none; | |
} | |
</style> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script> | |
var margin = {top: 200, right: 30, bottom: 200, left: 10}, | |
width = 960 - margin.right - margin.left, | |
height = 420 - margin.top - margin.bottom; | |
var x = d3.scale.linear() | |
.domain([0, 10000]) | |
.range([0, width]); | |
var y = d3.scale.linear() | |
.range([0, height]); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width + margin.right + margin.left) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
svg.append("rect") | |
.attr("class", "grid-background") | |
.attr("width", width) | |
.attr("height", height) | |
svg.append("g") | |
.attr("class", "grid") | |
.attr("transform", "translate(0," + height + ")") | |
.call(d3.svg.axis().scale(x).ticks(100).tickSize(-5)) | |
svg.append("g") | |
.attr("class", "grid") | |
.attr("transform", "translate(0,10)") | |
.call(d3.svg.axis().scale(x).ticks(20).tickSize(-10)) | |
svg.append("g") | |
.attr("class", "grid") | |
.attr("transform", "translate(0," + height + ")") | |
.call(d3.svg.axis().scale(x).ticks(10).tickSize(-20)) | |
.selectAll(".tick") | |
.data(x.ticks(10), function(d) { return d; }) | |
.exit() | |
.classed("minor", true); | |
svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(d3.svg.axis().scale(x).ticks(0)); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment