Built with blockbuilder.org
forked from LauraCortes's block: Tarea 4: Indicadores
forked from LauraCortes's block: Tarea 4: Indicadores
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
.bar {
fill: steelblue;
}
.bar:hover {
fill: brown;
}
.axis {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
display: none;
}
#filter{
font: 15px sans-serif;
color:#B40431;
}
</style>
</head>
<body>
<div id="filter">
<b>Countries:</b>
</div>
<div id="chart">
</div>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/queue.v1.min.js"></script>
<script>
//Márgenes
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// Definig selector
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
var dropDown = d3.select("#filter").append("select")
.attr("name", "country-list");
//axis
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(10, "%");
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.l + margin.r)
.attr("height", height + margin.t + margin.b);
//multiple loads
queue()
.defer(d3.csv,"datos.csv")
.defer(d3.csv,"Switzerland.csv")
.await(loadData)
//load file
function loadData (error,data,pais){
//d3.csv("datos.csv", type, function(error, data) {
if (error) throw error;
//load countries in the selector
var options = dropDown.selectAll("option")
.data(data)
.enter()
.append("option");
options.text(function (d) { return d.Rank+". " + d.Country; })
.attr("value", function (d) { return d.Country; })
.attr("id", function (d) { return d.Rank; });
//Add axis x
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("x",width)
.text("Features");
//Add axis y
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Score");
//load the graph
svg.selectAll(".bar")
.data(pais)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.feature); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.value); })
.attr("height", function(d) { return height - y(d.value); });
//});
}
function type(d) {
d.frequency = +d.frequency;
return d;
}
</script>
</body>
Modified http://d3js.org/topojson.v1.min.js to a secure url
Modified http://d3js.org/queue.v1.min.js to a secure url
https://d3js.org/d3.v4.min.js
https://d3js.org/d3.v3.min.js
https://d3js.org/topojson.v1.min.js
https://d3js.org/queue.v1.min.js