Skip to content

Instantly share code, notes, and snippets.

@d3indepth
Last active August 22, 2016 17:38
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 d3indepth/65fec76009499a2cd17d902021528e23 to your computer and use it in GitHub Desktop.
Save d3indepth/65fec76009499a2cd17d902021528e23 to your computer and use it in GitHub Desktop.
Axis with formatting
license: gpl-3.0
height: 200
border: no
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>SVG Axis</title>
</head>
<style>
path {
fill: none;
stroke: #aaa;
}
</style>
<body>
<svg width="700" height="40">
<g class="axis" transform="translate(20, 20)" />
</svg>
<script src="//d3js.org/d3.v4.min.js"></script>
<script>
var scale = d3.scaleLinear().domain([0, 1000000]).range([0, 600]);
var format = d3.format(",");
var axis = d3.axisTop().scale(scale)
.tickFormat(function(d) {
return '£' + format(d);
})
.ticks(5);
d3.select('.axis')
.call(axis);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment