D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
gigiaa
Full window
Github gist
Barchart- Gender balance in the parliaments of the world in 2013
<html> <head> <title>Gender balance in the parliaments of the world, 2013</title> <script type="text/javascript" src="https://d3js.org/d3.v3.min.js"> </script> <style type="text/css"> body { background-color: ivory; font-family: sans-serif; } h1 { font-size: 22px; margin: 0; font-family: verdana; } p { font-size: 16px; margin: 10px 0 0 0; font-family: arial; } svg { background-color: ivory; } rect:hover { fill: cadetblue; } .axis path, .axis line { fill: none; stroke: cadetblue; shape-rendering: crispEdges; } .axis text { font-family: arial; font-size: 12px } .y.axis path, .x.axis line { opacity: 0; } </style> </head> <body> <h1> Gender Balance in the parliaments of the world- 2013 </h1> <p>Percentage of parliamentary seats held by women expressed as a ratio of those held by men - source: UNDP 2014</p> <script type="text/javascript"> var w = 1000; var h = 2000; var padding = [20, 10, 50, 150]; //top, right, bottom, left var widthScale = d3.scale.linear() .range([ 0, w - padding[1] - padding[3] ]); var heightScale = d3.scale.ordinal() .rangeRoundBands([ padding[0], h - padding[2] ], 0.3); var xAxis = d3.svg.axis() .scale(widthScale) .orient("bottom"); var yAxis = d3.svg.axis() .scale(heightScale) .orient("left"); var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); d3.csv("database.csv", function(data) { data.sort(function(a, b) { return d3.descending(+a.year_2013, +b.year_2013); }); widthScale.domain([ 0, d3.max(data, function(d){ return +d.year_2013; }) ]); heightScale.domain(data.map(function(d) { return d.Country; } )); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", padding[3]) .attr("y", function(d) { return heightScale(d.Country); }) .attr("width", function(d) { return widthScale(d.year_2013); }) .attr("height", heightScale.rangeBand()) .attr("fill", "mediumvioletred") .append("title") .text(function(d) { return d.Country + "'s rate of women in parliament is " + d.year_2013; }); 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> </body> </html>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js