xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>OCDE's GDP per capita</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: white;
font-family: Helvetica, Arial, sans-serif;
}
svg {
background-color: #EBF2DE;
}
rects {
background-color: #000000;
shape-rendering: crispEdges;
}
rect:hover {
fill: #C2E3E8;
}
.axis path,
.axis line {
fill: none;
opacity: 0;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 12px;
}
</style>
</head>
<body>
<svg width="1000">
<ellipse cx="10" cy="10" rx="100" ry="100" fill="#B8CCB8" />
<ellipse cx="75" cy="75" rx="50" ry="50" fill="#D9FFFF" />
<text x="65" y="80" fill="charcoal" font-size="36" font-weight="bold" font-family="Helvetica">Gross Domestic Produt (GDP) per capita in 2013</text>
<text x="65" y="105" fill="charcoal" font-size="14" font-weight="bold" font-family="Helvetica">Total, US dollars/capita, 2013 - Source: Aggregate National Accounts, Gross domestic product</text>
<script type="text/javascript">
var w = 1000;
var h = 500;
var padding = [20, 10, 30, 115];//[top, right, bottom, left]
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
var widthScale = d3.scale.linear()
.range([ 0, w - padding[1] - padding[3] - 15]);
var heightScale = d3.scale.ordinal()
.rangeRoundBands([ padding[0], h - padding[2] ], 0.2);
var xAxis = d3.svg.axis()
.scale(widthScale)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(heightScale)
.orient("left");
d3.csv("gdppercapita.csv", function(data) {
data.sort(function(a, b) {
return d3.descending(+a.YR2013, +b.YR2013);
});
widthScale.domain([ 0, d3.max(data, function(d) {
return +d.YR2013;
}) ]);
heightScale.domain(data.map(function(d) { return d.Location; } ));
var rects = svg.selectAll("rect")
.data(data)
.enter()
.append("rect");
rects.attr("x", padding[3])
.attr("y", function(d) {
return heightScale(d.Location);
})
.attr("width", function(d) {
return widthScale(d.YR2013);
})
.attr("height", heightScale.rangeBand())
.attr("fill", "#87A7C4")
.append("title")
.text(function(d) {
return d.Location + "'s GDP per capita in 2013 was US$ " + d.YR2013;
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(" + padding[3] + "," + (h - padding[2]) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3] - 5) + ",0)")
.call(yAxis);
});
</script>
</svg>
</body>
</html>
Modified http://d3js.org/d3.v3.js to a secure url
https://d3js.org/d3.v3.js