D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
Beaupe
Full window
Github gist
Wk 5 Hwk
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Gender Inequality Indices</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; } h1 { font-size: 24px; margin: 0; } p { font-size: 14px; margin: 10px 0 0 0; } svg { background-color: white; } circle:hover { fill: orange; } .axis path, .axis line { fill: none; stroke: black; shape-rendering: crispEdges; } .axis text { font-family: sans-serif; font-size: 7px; } </style> </head> <body> <p><b>Women's Share of Government in Relation to Education</b></p> <p> % of Seats in Parliament Held by Women (Y) in Relation to % of Female Population with a Minimum of Secondary Education (X)</p> <p>Source: data.un.org, Gender Inequality Indices 2013 <script type="text/javascript"> var w = 800; var h = 800; var padding = [30, 10, 15, 50]; //Top, right, bottom, left var xScale = d3.scale.linear() .range([padding[3], w-padding[1]]); var yScale = d3.scale.linear() .range([h - padding[2],padding[0]]); var xAxis = d3.svg.axis() .scale(xScale) .orient("bottom") .ticks(10) .tickFormat(function(d) { return d + "%"; }) var yAxis = d3.svg.axis() .scale(yScale) .orient("left") .ticks(6) .tickFormat(function(d) { return d + "%"; }) var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); var cValue = function(d) { return d.Region;} color = d3.scale.category20(); d3.csv("GenderInequalityIndicesWk5Hwk.csv",function(data) { // data.sort(function(a, b) { //return d3.descending(a.ShareSeatsParliament, b.ShareSeatsParliament); // return d3.descending(+a.ShareSeatsParliament, +b.ShareSeatsParliament); // }); xScale.domain([ 0, d3.max(data, function(d) { return +d.PopulationWithSomeSecondaryEducationF; }) ]); yScale.domain([ 0, d3.max(data, function(d) { return +d.ShareSeatsParliament+10; }) ]); svg.selectAll("circle") .data(data) .enter() .append("circle") .attr("cx", function(d) { return xScale(d.PopulationWithSomeSecondaryEducationF);}) .attr("cy", function(d) { return yScale(d.ShareSeatsParliament);}) .attr("r", 3) .style("fill", function(d) { return color(cValue(d));}) .append("title") .text(function(d) { return d.Country + "'s women's share of seats in Parliament is " + d.ShareSeatsParliament; }) svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + (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.js
to a secure url
https://d3js.org/d3.v3.js