D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
P3nny
Full window
Github gist
Bar Chart 2: Wahlbeteiligung in Kölner Veedeln
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Cleaning Up</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> body { background-color: white; font-family: Tahoma, Arial, sans-serif; } h1 { font-size: 20px; margin: 1; color: #4D4D4D; } p { font-size: 16px; margin: 10px 0 0 0; color: #4D4D4D; } svg { background-color: white; } rect:hover { fill: #F16A6F; } .axis path, .axis line { fill: none; stroke: #4D4D4D; shape-rendering: crispEdges; } .axis text { font-family: sans-serif; font-size: 9px, font-weight: bold, font-color: #4D4D4D; } .y.axis path, .y.axis line { opacity: 0; } </style> </head> <body> <h1>Wahlbeteiligung in den Kölner Veedeln</h1> <p>Kölner Veedel: Anteil Wahlbeteiligung an der Gesamtzahl der Wahlbeteiligten. Source: <a href="https://www.offenedaten-koeln.de/dataset/wahlbeteiligung-2014">Offene Daten Köln</a>, Kommunalwahl 2014</p> <script type="text/javascript"> var w = 600; var h = 1600; var padding = [ 28, 10, 20, 200 ]; //Top, right, bottom, left var widthScale = d3.scale.linear() .range([ 1, w - padding[1] - padding[3] ]); var heightScale = d3.scale.ordinal() .rangeRoundBands([ padding[0], h - padding[2] ], 0.15); var xAxis1 = d3.svg.axis() .scale(widthScale) .orient("top"); var xAxis2 = 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("veedel.csv", function(data) { data.sort(function(a, b) { return d3.descending(+a.wahlbeteiligung, +b.wahlbeteiligung); }); widthScale.domain([ 0, d3.max(data, function(d) { return +d.wahlbeteiligung; }) ]); heightScale.domain(data.map(function(d) { return d.veedel; } )); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", padding[3]) .attr("y", function(d) { return heightScale(d.veedel); }) .attr("width", function(d) { return widthScale(d.wahlbeteiligung); }) .attr("height", heightScale.rangeBand()) .attr("fill", "#8BDBD9") .append("title") .text(function(d) { return d.wahlbeteiligung + "% Wahlbeteiligung in " + d.veedel; }); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(" + padding[3] + "," + (h - padding[2]) + ")") .call(xAxis2); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(" + padding[3] + "," + padding[0] + ")") .call(xAxis1); svg.append("g") .attr("class", "y axis") .attr("transform", "translate(" + padding[3] + ",0)") .call(yAxis); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js