Skip to content

Instantly share code, notes, and snippets.

Last active October 9, 2018 07:58
What would you like to do?
<!DOCTYPE html>
<svg width="800" height="500"><g transform="translate(350,50)"></g></svg>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
var formatPercent = d3.format(".0%"),
formatNumber = d3.format(".0f");
var threshold = d3.scaleThreshold()
.domain([1, 50, 200, 500, 1000, 2000, 4000])
var x = d3.scaleSqrt()
.domain([1, 4500])
.range([0, 300]);
var xAxis = d3.axisBottom(x)
var g ="g").call(xAxis);".domain")
.data(threshold.range().map(function(color) {
var d = threshold.invertExtent(color);
if (d[0] == null) d[0] = x.domain()[0];
if (d[1] == null) d[1] = x.domain()[1];
return d;
.enter().insert("rect", ".tick")
.attr("height", 8)
.attr("x", function(d) { console.log(d[0]); return x(d[0]); })
.attr("width", function(d) { return x(d[1]) - x(d[0]); })
.attr("fill", function(d) { return threshold(d[0]); });
.attr("fill", "#000")
.attr("font-weight", "bold")
.attr("text-anchor", "start")
.attr("y", -6)
.text("Dân số trên km²");
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment