Skip to content

Instantly share code, notes, and snippets.

@d3indepth
Last active January 22, 2020 15:55
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/30d31098b607b669a7874bf4ab3c9595 to your computer and use it in GitHub Desktop.
Save d3indepth/30d31098b607b669a7874bf4ab3c9595 to your computer and use it in GitHub Desktop.
scaleLog example
license: gpl-3.0
height: 90
border: no
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Log scale</title>
</head>
<style>
body {
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 10px;
color: #333;
}
text {
fill: black;
}
</style>
<body>
<svg width="800" height="80">
<g id="wrapper" transform="translate(40, 40)">
</g>
</svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script>
var logScale = d3.scaleLog()
.domain([10, 100000])
.range([0, 700]);
var myData = [10, 100, 1000, 10000, 100000];
d3.select('#wrapper')
.selectAll('text')
.data(myData)
.enter()
.append('text')
.attr('x', function(d) {
return logScale(d);
})
.text(function(d) {
return d;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment