Skip to content

Instantly share code, notes, and snippets.

@63anp3ca
Created August 29, 2018 13:44
Show Gist options
  • Save 63anp3ca/54edfeb87e3b51ff8deadc55897cd227 to your computer and use it in GitHub Desktop.
Save 63anp3ca/54edfeb87e3b51ff8deadc55897cd227 to your computer and use it in GitHub Desktop.
fresh block
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
</style>
</head>
<body>
<script>
consulta = d3.json("https://raw.githubusercontent.com/john-guerra/consultaAnticorrupcion2018/master/consulta_anticorrupcion_municipios.json");
d3 = require("d3");
const svg = d3.select(DOM.svg(width, height));
const x = d3.scaleLinear()
.domain([0, d3.max(consulta, d=> d.censo)])
.range([0, width])
const rects = svg.selectAll(".bar")
.data(consulta.sort( (a,b) => d3.descending(a.censo, b.censo)) );
rects.enter()
.append("rect")
.attr("class", "bar")
.attr("x", 0)
.attr("y", (d,i, ds) => i*10)
.attr("width", d => x(d.censo))
.attr("height", 9)
.style("fill", "steelblue");
const texts = svg.selectAll(".label")
.data(consulta.sort( (a,b) => d3.descending(a.censo, b.censo)) );
rects.enter()
.append("text")
.attr("class", "label")
.attr("x", 0)
.attr("y", (d,i, ds) => i*10)
.text( d=> d.municipio)
// .attr("width", d => x(d.censo))
// .attr("height", 9)
.style("fill", "#333")
.style("font-size", "6pt")
.style("font-family", "sans-serif");
//return svg.node();
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment