Skip to content

Instantly share code, notes, and snippets.

@enjalot
Last active February 22, 2016 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/2f0f6176a0a2473a560d to your computer and use it in GitHub Desktop.
Save enjalot/2f0f6176a0a2473a560d to your computer and use it in GitHub Desktop.
tickValues
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
svg { width: 100%; height: 100%; font-family: Helvetica, Arial, _sans; font-size: .75em; }
.axis text {
font: 10px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.caption {
font-weight: bold;
}
</style>
</head>
<body>
<script>
var vertigo = [1,2,3,14];
var width = 960,
height = 500;
var x = d3.scale.linear()
.domain([0, 100])
.range([1, 600])
var xAxis = d3.svg.axis()
.scale(x).tickSize(13)
.tickValues([0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
.tickFormat(function(n) { return n + "%"})
.orient("bottom");
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + (width-600) / 2 + "," + height / 2 + ")");
svg.append("g")
.attr("class", "x axis")
.call(xAxis);
svg.call(xAxis).append("text")
.attr("class", "caption")
.attr("y", -9)
.text("tickValues");
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment